这是我第一次尝试本地化,我读得越多,就越感到困惑。老实说,我现在只是在寻找答案。以下是我遇到的错误:
未处理的异常:System.Resources.MissingManifestResourceException:找不到适用于指定区域性或中性区域性的任何资源。请确保“MeetnGreetSf.Resources.AppResources.resources”在编译时已正确嵌入或链接到程序集“MeetnGreetSf”,或者所需的所有卫星程序集都可以加载并完全签名。
以下是类:
public class TranslateHelper
{
readonly CultureInfo ci;
private string ResourceId = "MeetnGreetSf.Resources.AppResources";
private ResourceManager resmgr;
private CultureInfo cui = new CultureInfo("es-ES");
public TranslateHelper()
{
//ResourceId += "." + cui.Name;
resmgr = new ResourceManager(ResourceId, typeof(AppResource).GetTypeInfo().Assembly);
}
public string Translate(string Name)
{
var translation = resmgr.GetString(Name, ci);
return translation;
}
}
我觉得我很接近了,但不知为何它将文件附加为“.resources”而不是“.resx”?
提前感谢任何帮助。
忘记说明如何使用翻译类了。
public Colors()
{
colorInfo = new ObservableCollection<ColorType>();
t = new TranslateHelper();
this.GenerateColors();
}
private void GenerateColors()
{
colorInfo.Add(new ColorType(t.Translate("Aqua"), Color.Aqua));
colorInfo.Add(new ColorType(t.Translate("Black"), Color.Black));
colorInfo.Add(new ColorType(t.Translate("Blue"), Color.Blue));
colorInfo.Add(new ColorType(t.Translate("Gray"), Color.Gray));
colorInfo.Add(new ColorType(t.Translate("Green"), Color.Green));
colorInfo.Add(new ColorType(t.Translate("Lime"), Color.Lime));
colorInfo.Add(new ColorType(t.Translate("Maroon"), Color.Maroon));
colorInfo.Add(new ColorType(t.Translate("Navy"), Color.Navy));
colorInfo.Add(new ColorType(t.Translate("Olive"), Color.Olive));
colorInfo.Add(new ColorType(t.Translate("Purple"), Color.Purple));
colorInfo.Add(new ColorType(t.Translate("Red"), Color.Red));
colorInfo.Add(new ColorType(t.Translate("Silver"), Color.Silver));
colorInfo.Add(new ColorType(t.Translate("Teal"), Color.Teal));
colorInfo.Add(new ColorType(t.Translate("White"), Color.White));
colorInfo.Add(new ColorType(t.Translate("Yellow"), Color.Yellow));
}
}