In this second part of Multilanguage Applications we will explain how create an application multilanguage with a no official Android Language. As example Catalan, Catalan is a Language from Catalonia a region from Spain.
with the next code we can load an no official Language:
String LoadLanguage = “ca”;
Locale languageTel = new Locale(LoadLanguage);
Configuration configuracion = new Configuration();
configuracion.languageTel = languageTel;
So with this code we force to load catalan Language. If yo need more help about Multilanguage applications read the firs post about Multilanguage applications.
In this post I will explain how make a Multilanguage Android application. Make an application Multilanguage is very easy. So let’s go with the explanation.
Structure of application
The first thing to remember is to avoid insert text in the code and instead use the file strings.xml in the folder values. For each language we must have a file string.xml that will be inserted in his corresponding folder. The folder structure is basically the name of the folder and the language suffix as example, values-es. The folder without the suffix will be the default language. This folder rule is applicable to all the folder resources,as drawable and raw.
What to do in the code application?
In the code of the application to use the multilanguage we must to do the next:
String cadena = getResources().getString(R.string.next);
How obtain the language of a telephone?
If we want to obtain the language of the telephone we need the next code, we have two methods to obtain the language:
- String locale = this.getResources().getConfiguration().locale.getDisplayName();
- locale = java.util.Locale.getDefault().getDisplayName();
So I hope this Post have helped to solve your problems… If you have a question no doubt to ask I will try to help