英文:
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 ??
专注分享java语言的经验与见解,让所有开发者获益!
评论