Python怎么设置中文:Android更改中文和繁体中文的区域设置不起作用

关于Python怎么设置中文的问题,在working chinese中经常遇到, 在我的应用程序中,我可以选择从中文切换到繁体中文。

在我的应用程序中,我可以选择从中文切换到繁体中文。

我正在使用微调器,其中位置 1 是中文,2 是繁体中文。当选择位置 1 时,这里是我的代码,它切换语言

if (pos == 0) 
{
   langSelected ="en";
}               
else if (pos == 1) 
{
   langSelected ="zh";
}               
else if (pos == 2)
{
  langSelected ="zh-rTW";
}
Locale locale = new Locale(lang);           
Locale.setDefault(locale);
android.content.res.Configuration config = new android.content.res.Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
@Override
public void onConfigurationChanged(android.content.res.Configuration newConfig) 
{
    super.onConfigurationChanged(newConfig);
    if (locale != null){
        newConfig.locale = locale;
        Locale.setDefault(locale);
        getBaseContext().getResources().updateConfiguration(newConfig, getBaseContext().getResources().getDisplayMetrics());
     }
}

当使用微调器从英语切换到中文时,正确的语言被加载,但是当加载繁体中文(zh-rTW)时,只有中文文本被加载

我在 values-zh 中有我的简体中文文本,因为我在 values-zh-rTW 中加载了繁体中文文本

应用程序名称因每种语言而异,所以我也尝试从设备设置更改语言,现在也以简体中文加载正确,但繁体中文未加载。但这里的应用程序名称被更改为繁体中文,即应用程序名称从值-zh-rTW 加载

我哪里错了,我应该改变繁体中文的文件夹吗?

6

我知道这是一个迟到的帖子,但希望它能帮助别人。

解决方案是使用国家名称简单地创建一个 Locale。这意味着Locale类已经声明了一些静态区域设置。例如:-

中国区域设置-https://developer.android.com/reference/java/util/Locale.html#CHINA

区域设置-https://developer.android.com/reference/java/util/Locale.html#TAIWAN

所以简单地说,解决方案是:-

Locale locale;
if(lang.equals("zh-rTW"))
    locale = Locale.TAIWAN;
else(lang.equals("zh-rCN")
    locale = Locale.CHINA;
else
    //handle other languages
4

此代码更改中文简体和繁体的区域设置:

public void setAppLocale(Context context, String languageCode, String countryCode){
    Resources resources = context.getResources();
    Locale locale = new Locale(languageCode, countryCode);
    Locale.setDefault(locale);
    Configuration configuration = new Configuration();
    configuration.setLocale(locale);
    resources.updateConfiguration(configuration, resources.getDisplayMetrics());
}
0

根据我的经验,最好有values-zh-rCN为简体中文和values-zh-rTW为繁体中文。此外,这可能已经是你在代码中的某个地方做的事情,手动更改区域设置需要重新加载活动才能生效。

本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处

(309)
好搜排名优化软件:在街机游戏中优化数据库高分排名
上一篇
Python全文检索:如何使用Elsevier文章检索API获取论文全文
下一篇

相关推荐

发表评论

登录 后才能评论

评论列表(14条)