Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android. How to use the same localizable messages for all the languages in a country?

My country (Spain) has several languages (es-ES, ca-ES, gl-ES, eu-ES). We won't add all the languages for now so we would like to use main language in Spain, i.e. Spanish (es). We would like to display the /values-es/strings.xml when the user has selected one of the other languages in the country. How can we do that?

Oh, and we would like to use English as the default language (/values/strings.xml).

It would be great to have something like /values-ES/strings.xml, but I suppose that can't be done because the first code should be the language code.

Now we are copying the /values-es/strings.xml file to the other folders (values-ca, values-gl and values-eu) but we'd like to avoid that.

like image 311
Ferran Maylinch Avatar asked Jun 07 '14 13:06

Ferran Maylinch


1 Answers

I think that you should have only 2 folders with 1 strings.xml for each other:

  1. res/values/strings.xml this resource will contains your text in English ;
  2. res/values-es/strings.xml this resource will contains your text in Spanish .

When your app is installed on a device which is configured with the Italian language, it will use the file resource on case 1.

When your app is installed on a device which is configured with a Spanish language (and there are a lot of Spanish language out there, think about South America countries), it will use the file resource on case 2.

You can do it easily with Android Studio:

  1. right-click on res folder
  2. go to New > Android resource directory
  3. a window will show you some options; pick Locale and then click on the button with those symbols "> >"
  4. then on the Language list, pick es: Spanish and then click OK, as showed in the image below (note that by default the Specific Region Only has Any Region selected!)

Add locale image guide

By experience: I never faced up a Breton, Corsican or Provençal users claiming for a full translation of the application in their language (by default the app has English as default and French).

like image 121
JJ86 Avatar answered Oct 23 '22 09:10

JJ86