【问题标题】:Get specific string resource translation at application runtime在应用程序运行时获取特定的字符串资源翻译
【发布时间】:2019-06-28 12:14:18
【问题描述】:

在 Xamarin.Android 中,我有德语翻译的字符串资源和默认的英语翻译。当应用程序运行时,它只获取德语字符串。如何在不更改设备区域设置的情况下使其获得英文翻译?

<string name="exampleResource">Example string</string>

<string name="exampleResource">Beispiel string</string>

我需要在运行时在 Xamarin 应用程序中显示的第二个翻译。

【问题讨论】:

    标签: android xml resources translation android-resources


    【解决方案1】:

    您是否尝试过更改 resx 对象的文化?

     AppResources.Culture = new CultureInfo("en-EN");
    

    【讨论】:

    • 以下不起作用:CultureInfo englishGBCulture = new CultureInfo("en-GB"); CultureInfo.DefaultThreadCurrentCulture = englishGBCulture; CultureInfo.DefaultThreadCurrentUICulture = englishGBCulture; Thread.CurrentThread.CurrentCulture = englishGBCulture; Thread.CurrentThread.CurrentUICulture = englishGBCulture;
    • 对不起,我没有读到您正在使用本机 xamarin 工作。我认为这篇文章可以帮助您在文化线程更改后更新您的资源stackoverflow.com/questions/2644377/…
    • 我不能只为 GetString() 返回的值指定文化而不是更改整个应用程序的语言,即。 e. AppResources.ResourceManager.GetString(index, AppResources.Culture)?
    猜你喜欢
    • 2011-10-22
    • 1970-01-01
    • 2013-07-02
    • 1970-01-01
    • 2017-02-19
    • 1970-01-01
    • 2014-06-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多