.net 尝试在xaml xamarin表单中进行本地化

.net 尝试在xaml xamarin表单中进行本地化,.net,xaml,xamarin,xamarin.forms,resourcemanager,.net,Xaml,Xamarin,Xamarin.forms,Resourcemanager,我尝试使用TranslateExtension方法,该方法在xamarin表单的xaml本地化指南中进行了解释。然而,我得到了一个错误 Unhandled Exception: System.Resources.MissingManifestResourceException: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "CashRe

我尝试使用TranslateExtension方法,该方法在xamarin表单的xaml本地化指南中进行了解释。然而,我得到了一个错误

Unhandled Exception:

System.Resources.MissingManifestResourceException: Could not find any resources appropriate for the specified culture or the neutral culture.  Make sure "CashRegisterApp.Resx.AppResources.resources" was correctly embedded or linked into assembly "CashRegisterApp.Android" at compile time, or that all the satellite assemblies required are loadable and fully signed. occurred
调试后,我注意到由于某种原因,资源文件的扩展名被设置为.resources。由于这不是资源管理器的公共成员,我不确定如何将其设置为使用resx或resw文件


您需要为
资源指定当前区域性

var culture = "en-US";

AppResources.Culture = new System.Globalization.CultureInfo(culture);

当前程序集中的.resx资源字符串值来自名称为
MyNamespace
、路径为
resx\Resources.resx
和资源名称为
Key
的命名空间中的.resx文件。请注意,未定义任何区域设置:

string resourcesValue = MyNamespace.Resx.Resources.Key;
使用
System.Resources.ResourceManager
,如示例所示:

const string ResourceId=“MyAssembly.Resx.Resources”;
private static readonly Lazy ResMgr=new Lazy()
=>新的ResourceManager(ResourceId,typeof(MyClass).GetTypeInfo().Assembly));
...
string resMgrValue=ResMgr.Value.GetString(“键”);

它添加了一个区域性。即使没有,也应该使用默认的资源文件否,Android/iOS没有默认的区域性,AFAIK
const string ResourceId = "MyAssembly.Resx.Resources";

private static readonly Lazy<ResourceManager> ResMgr = new Lazy<ResourceManager>(()
        => new ResourceManager(ResourceId, typeof(MyClass).GetTypeInfo().Assembly));
...
string resMgrValue = ResMgr.Value.GetString("Key");