未从正确的资源中加载字符串,在多语言应用程序中。

huangapple 未分类评论44阅读模式
英文:

Not loading string from correct resource in multi language application

问题

我想要将波斯语添加到我的应用程序中。我创建了一个新的string.xml文件,命名为'fa',并使用以下函数在其中设置了翻译后的文本。我尝试了修改应用程序的语言:

public void loadLanguage() {
    Locale locale = new Locale(manager.getAppLanguage());
    Locale.setDefault(locale);
    Configuration cong = new Configuration();
    cong.locale = locale;
    getBaseContext().getResources().updateConfiguration(cong, getBaseContext().getResources().getDisplayMetrics());
}

我在MainActivity中的setContentView(R.layout.activity_main)之前调用了这个函数。

在运行应用程序并将语言更改为波斯语后,一切都正确地从左到右进行了更改,但仍然从英文资源加载字符串,所有文本仍然是英文。

有人知道为什么会发生这种情况吗?

英文:

I want to add Persian language to my application . i made a new string.xml file as 'fa' and set translated text there by using the following function I have tried to change the language of application :

    public void loadLanguage() {
    Locale locale = new Locale(manager.getAppLanguage());
    Locale.setDefault(locale);
    Configuration cong = new Configuration();
    cong.locale = locale;
    getBaseContext().getResources().updateConfiguration(cong , getBaseContext().getResources().getDisplayMetrics());
}

I call this function before setContentView(R.layout.activity_main); in my MainActivity .

after I run the application and change language to Persian everything change to RTL correctly but still string loaded from English resource and all text still are English.

Does anybody have an idea about why this happened ??

huangapple
  • 本文由 发表于 2020年4月10日 16:14:00
  • 转载请务必保留本文链接:https://java.coder-hub.com/61136403.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定