【问题标题】:Trying localization in xaml xamarin forms尝试以 xaml xamarin 形式进行本地化
【发布时间】:2018-08-01 11:22:39
【问题描述】:

我正在尝试使用 xamarin 表单的 xaml 本地化指南中解释的 TranslateExtension 方法。但是我遇到了一个错误。

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 文件。

【问题讨论】:

    标签: .net xaml xamarin xamarin.forms resourcemanager


    【解决方案1】:

    您需要为您的Resources 指定当前文化。

    var culture = "en-US";
    
    AppResources.Culture = new System.Globalization.CultureInfo(culture);
    

    【讨论】:

    • 它添加了一种文化。即使不是,它也应该使用默认资源文件
    • 不,Android/iOS 没有默认文化,AFAIK
    【解决方案2】:

    当前程序集中的 .resx 资源字符串值来自命名空间中名称为 MyNamespace、路径为 Resx\Resources.resx 和资源名称为 Key 的 .resx 文件,可以使用以下内容读取。请注意,没有定义语言环境:

    string resourcesValue = MyNamespace.Resx.Resources.Key;
    

    使用System.Resources.ResourceManager,如localization 示例:

    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");
    

    【讨论】:

      猜你喜欢
      • 2018-03-17
      • 2014-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-27
      相关资源
      最近更新 更多