【问题标题】:Changing the language manually to Simplifies Chinese手动将语言更改为简体中文
【发布时间】:2014-02-14 02:36:22
【问题描述】:

我使用此代码手动更改我的应用程序的语言:

Locale locale = new Locale(OneLanguageCode);   
Locale.setDefault(locale);  
Configuration config = new Configuration();  
config.locale = locale;  
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());       

我在 OneLanguageCode 中设置了国际代码。一切都适用于我尝试过的每个代码,如“en”、“es”、“fr”等等……但我用简体中文让自己发疯。 在这种情况下,我有一个名为 values-zh-rCN 的文件夹,其中有字符串。如果我将设备语言设置为简体中文,效果很好。但是没有办法用上面的代码手动设置。 我曾尝试使用“zh-CN”作为 OneLanguageCode 值,但也没有成功。以英文显示。

正如我所说,所有这些都适用于其他语言。我可以让人们使用荷兰语作为他们的设备默认语言,但在我的应用程序中使用法语。为什么我无法将荷兰语作为设备默认语言,但在我的应用中使用繁体中文?

感谢您的宝贵时间。

【问题讨论】:

    标签: android chinese-locale


    【解决方案1】:
    Locale locale = new Locale("en_CA"); 
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.locale = locale;
    context.getApplicationContext().getResources().updateConfiguration(config, null);
    

    【讨论】:

    • 你指的是哪个TranslationHelper
    • 是的,我在 setContentView 之前做所有事情。正如我所说,它适用于其他语言。 “翻译助手”是什么意思?谢谢
    【解决方案2】:

    感谢user2968888的帮助,我就是这样解决的:

    Locale locale;
    if(OneLanguageCode.equals("schinese")) //any tag here to know it is Simplified Chinese
       locale = Locale.SIMPLIFIED_CHINESE;
    else
       locale = new Locale(OneLanguageCode);
    Locale.setDefault(locale);  
    Configuration config = new Configuration();  
    config.locale = locale;  
    getApplicationContext().getResources().updateConfiguration(config, null);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-20
      • 2015-07-20
      • 2014-05-15
      • 2018-05-08
      • 1970-01-01
      • 2021-07-18
      • 1970-01-01
      相关资源
      最近更新 更多