Adding/Removing the language entries in the "Settings" -> "Select Locale" from Android phone

yaobin picture yaobin · Apr 1, 2011 · Viewed 32.4k times · Source

My question:

How can I add or remove the language entries in the "Settings" -> "Language & keyboard settings" -> "Select Locale"(or "Select Language") in the Android phone from the source code level?

I'll provide more details on what I want and what I have done. Please excuse me if I present any silly understanding or information. I'm pretty new to Android development, starting to learn it several days ago. There is still a lot that I don't know.

More info on what I want:

I'm recently working on a task to localize the entire phone product with new languages(I mean, I'm not working on a specific application. This is why I need to add a new locale in the Settings). When I got the development phone, I found there are only several language entries available in the "Select Locale", such as "English", "French" and "Spain". So first of all, I need to add and display some new language entries to this list, such as "Japanese", "Chinese", "Korean".

I have all the source code of Android platform and my own code, so I think this task can be done by modifying the source code or the resource files somewhere. Unfortunately, I don't know where the code and files are.

The "Hello, L10N" tutorial shows a way to add a new locale from "Custom Locale" at run-time. But what I want is to add the new locales at build time so when the phone is started up, the new locales will be displayed in the "Select Locale" directly without any other actions.

What I have done:

I did a lot of research on the internet before I come here. Here is what I found:

  1. Sinkiru in Stackoverflow asked a question about what I am exactly looking for. See it here. However, nobody else replied him. His own reply only tells where to query the CURRENT language setting, which is not what I want. I personally sent him an email for this question but haven't got his reply.

  2. I searched a lot in Stackoverflow, with the keywords "android locale", "android language", "android new locale" and something similar. Most of the questions in this site are asking how to change the locale of an app, how to add multi-language support for an app, etc.. They are NOT what I want.

  3. I searched a lot in the android-platform Google group(http://groups.google.com/group/android-platform). Some people are asking my question, but after reading through the messages I still don't get my answer.. :-( Here is a list of the posts I read in the group(and I do not get what I want from them):

  4. Back to the entry "(a)" listed above. In the "OS localization" message thread, Dianne Hackborn, an Android framework engineer, said the following:

"The settings app just shows you all of the locales that are available in the platform resources. Adding strings for a new locale should automatically have those shown in settings. You tell the build system which locale resources to include when it does the build... unfortunately I can't help you on that part, but maybe someone else can."

His words in bold suggest that my task might be done automatically by adding new locale resource to the source code, and by setting up or changing something in the build system. I'm wondering if someone here has ever done the similar thing before? I'm going to give a try tomorrow.

  1. Last but not least, I searched in the official Android developer site. In the "Run and Test the Localized Application" of the "Hello, L10N" tutorial it says something about the available locales in the "Settings" application, but that is basically talking about what to do in the emulator and this shouldn't be what I need. I want it done on a real phone.

  2. I had also dived into the Android platform source code trying to discover something. I started at the $(ANDR_SRC_ROOT)/Packages/app/Settings/src/.../LocalePicker.java. In the LocalePicker::onCreate() method, I noticed this line of code:

    String[] locales = getAssets().getLocales();

The code below this line tries to set all the obtained locale names to an ArrayAdapter and then set the adapter to the list view to show. Thus I think the "getLocales()" method is the key to the solution.

I then looked into the getLocales() code. getLocales() is a member method of AssetManager and is declared as native, hence I stepped into the $(ANDR_SRC_ROOT)/frameworks/base/libs/utils/AssetManager.cpp which I GUESS should be the actual implementation of the java getLocales() method. The C++ AssetManager::getLocales() finally leads me to the C++ ResTable::getConfigurations() method in which a member variable "mPackageGroups" is scanned through to retrieve all the available ResTable_config items. Thus I think all the available locales should be added into this mPackageGroups during the system started up. However, I lost in the code at last and couldn't find where the locales are added to the mPackageGroups.

Answer

insink71 picture insink71 · Jun 7, 2012

on HTC phones you must also modify /system/customize/CID/default.xml ... That is the file they use to specify locales on their stock roms. If the rom is a WWE, supposedly editing CID is all one need do, but this doesn't always hold true.