I have created a bilingual (having two languages) android application. I have inserted my resource strings in two files:
For Persian language (default)
values/st
You can make class which extends Application
. There you can override one method which gets called everytime you change configuration (example when screen orientation gets changed).
Something like:
public class MyApplication extends Application {
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setLocale();
}
private void setLocale() {
Locale locale = new Locale("fa_IR");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
}
}
And dont forget to declare it in the manifest: example of Application class
In AndroidManifest.xml: