Search code examples
javaandroidxmllocalesetlocale

Create "values-en" folder dynamically in android


First of all sorry for my weak english.

I was searching for how to change language of my android application. I found in lots of link saying that creating values-fr (for french), values-en (for english) etc and copying strings.xml file into those folders. And replace string names inside strings.xml according to language. Finally adding some code blocks which say that which "values folder" will be used (see code block below), I can achieve language support.

String languageToLoad  = "en"; // your language
Locale locale = new Locale(languageToLoad);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
                    getBaseContext().getResources().getDisplayMetrics());

But I was wondering that is it possible to create "values-any" file in runtime and after creating, is it possible to put strings.xml file inside that folder which is filled before and assume that the strings.xml file coming from some database or webservice.

Briefly is it possible to achieve language support dynamically? Any idea will be greatly appreciated. Thanks in advance.


Solution

  • I was wondering that is it possible to create "values-any" file in runtime

    No. Resources are read-only at runtime.

    is it possible to achieve language support dynamically?

    Not through the Android resource system.