Tag Archive for obtain language

MultiLanguage Applications II for android (no official Languages)

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);
Locale.setDefault(languageTel);
Configuration configuracion = new Configuration();
configuracion.languageTel = languageTel;
getBaseContext().getResources().updateConfiguration(configuracion, getBaseContext().getResources().getDisplayMetrics());

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.

MultiLanguage Applications Android

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.

  • drawable-hdpi
  • drawable-ldpi
  • drawable-mdpi
  • drawable-es-hdpi
  • drawable-es-ldpi
  • drawable-es-mdpi
  • raw
  • raw-es
  • values
  • values-es

What to do in the code application?

In the code of the application to use the multilanguage we must to do the next:

XML code

<Button
     android:layout_width=”wrap_content”
     android:layout_height=”wrap_content”
     android:text=”@string/next” />  

Java code

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:

  1. String locale = this.getResources().getConfiguration().locale.getDisplayName();
  2. 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 :)

Seo Packages