Saturday 2 August 2014

Android: Supporting multiple language(Localization) in android apps

We can support different language in our Android application using resources file.
I am adding here example for the same.

We are going to support English, Hindi & Marathi language in this demo for this we have to create separate resources folder for all the three language and we will put different resource file in this folder and then we can change application locale using below code :

public static void setLocale(Context context, String locale) {
Locale myLocale = new Locale(locale);
Resources res = context.getResources();
DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
conf.locale = myLocale;
res.updateConfiguration(conf, dm);
}

We have to add three different string resource folder (e.g values-hi, values-en, values-ma) with resource file string.xml. Now when we will change application locale, application will automatically choose appropriate resource folder for rendering it on application.

Similarly we can also use different image resources in our application for that we have to create different drawable folder (eg. drawable-hi, drawable-en, drawable-ma) now we can put different image with same name in this drawable resource.


You can download example from below url:
https://drive.google.com/file/d/0B0mH97AUwQqhM0t2RXdMb3QxVHc/edit?usp=sharing

4 comments:

  1. Dipen, if you need a tool to easier manage the localization of resource files, have a look at the software translation platform https://poeditor.com/

    It has Github integration, and other features that can help automate the workflow, like API and Translation Memory.

    ReplyDelete
  2. creativity of writer is purely impressive. It has touched to the level of expertise with his writing. Everything is up to the mark. Written perfectly and I can use such information for my coming assignment.apk downloader

    ReplyDelete