Localization Of Android Application. One String Resources For Several Countries
I have such a question: I have an Login/Registration Activity which is by default is using Russian version of strings.xml. So when user is entering application - he sees text in Ru
Solution 1:
I would strongly recommend using lokalise
We have an app with 6 flavours and more than 16 languages. It would be a nightmare, if only this library didn't exist.
They have a tutorial on how to use custom locale: but in short:
// Create a new Locale objectLocalelocale=newLocale("ru");
Locale.setDefault(locale);
// Create a new configuration objectConfigurationconfig=newConfiguration();
// Set the locale of the new configuration
config.locale = locale;
// Update the configuration of the Accplication context
getResources().updateConfiguration(
config,
getResources().getDisplayMetrics()
);
Solution 2:
What you want to do is:
Have a list of language/locale wise content translations in the format of key-value pairs. You can achieve this within the same file or have separate files and name them according to the language-locale combo. I prefer the latter version, easier to maintain.
Next at time of app init, you want to read the phone's current locale with
Localecurrent= getResources().getConfiguration().locale;
Map this value to the content files (varies from framework to framework) created above and you have instant localization.
Post a Comment for "Localization Of Android Application. One String Resources For Several Countries"