I have two locale in my application. Can I access to resources, for example string array from different locale without to change current locale ? I mean with coding I don't like to change it in Settings.
You'll find this screen either in the System Settings app: Languages, or System Settings: System: Languages and input. The Language preference screen should contain one entry called “English (Europe)”. Click Add language and add a fallback language.
With Locale®, you create situations specifying conditions under which your phone's settings should change. For example, your "At Work" situation notices when your Location condition is "77 Massachusetts Ave.," and changes your Volume setting to vibrate.
Localizing Strings In order to localize the strings used in your application , make a new folder under res with name of values-local where local would be the replaced with the region. Once that folder is made, copy the strings. xmlfrom default folder to the folder you have created. And change its contents.
drawable for all drawable resources) and for each resource of that type, there is a static integer (for example, R. drawable. icon ). This integer is the resource ID that you can use to retrieve your resource.
The better solution would be (if you're on API 17):
@NonNull
protected String getEnglishString() {
Configuration configuration = getEnglishConfiguration();
return getContext().createConfigurationContext(configuration).getResources().getString(message);
}
@NonNull
private Configuration getEnglishConfiguration() {
Configuration configuration = new Configuration(getContext().getResources().getConfiguration());
configuration.setLocale(new Locale("en"));
return configuration;
}
Here is the code that work for me if cMK is String array from current locale and cEN is string array from diffrent locale
cMK = getResources().getStringArray(R.array.cities);
Configuration confTmp =new Configuration( getResources().getConfiguration());
confTmp.locale = new Locale("en");
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
Resources resources = new Resources(getAssets(), metrics, confTmp);
/* get localized string */
cENG = getResources().getStringArray(R.array.cities);
The current locale isn't changed and that was the point.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With