Localization in Google Android

19 May 2010

Any localization will require the user to provide a sort of dictionary, XML or a resources bundle, which contains a mapping between the actual string text of the label and the converted text in the desired language. This is the direct way to do it. Localization does not intend to 'automatially' convert the string into its localized equaivalent. This is because language conversion is in itself a very intense process (algorithmically) and cannot be handled by a stand alone 'converter' application. And, even if such an API or plugin is present, I would suggest not using it, as its accuracy is not always 100%. Infact, web and desktop based language converters are still being developed to provide higher and higher accuracies.
So it ultimatly boils down to the individual application maintaning its own ditionary. In a way this is better, this gives developers more control over the application, and the behaviour is not unpredictable, which would be the case if the app relies on external 3rd party language converters. That being said, here is how its done.

On Android,

Assuming you use the default Android application development environment and code structure (is there anything other than default? :D ) -
  1. Copy the res/values/strings.xml bundle to res/values-es/strings.xml (Espanol/ Spannish)
  2. Replace all the Spannish text here with the Spannish text as shown. Use Google translate (link below)
  3. Copy the contents of res/drawable bundle to res/drawable-es-rES (Espanol/ Spannish)
  4. Replace the drawable resource files (your png files) to its any Spannish equivalents.
  5. Note: If the equivalent of a string or drawable is not found in the language directories, the default values are taken from the res/values and res/drawable folders.
  6. All references using android:text="@string\englishtext", etc. will display the equivalent Spannish text if the user chooses Spannish as the device language.
  7. Similarly, all drawable items wil show the Spannish equivalents, if it exists, or display the default drawables.
  8. Localization almost always gets precedence for a user.
  9. Use
    String locale = context.getResources().getConfiguration().locale.getDisplayName();
    to get the localization being used.
Use:-