Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding/Removing the language entries in the "Settings" -> "Select Locale" from Android phone
    text
    copied!<h3>My question:</h3> <p>How can I add or remove the language entries in the "Settings" -> "Language &amp; keyboard settings" -> "Select Locale"(or "Select Language") in the Android phone from the <strong>source code</strong> level?</p> <p>I'll provide more details on what I want and what I have done. <strong>Please excuse me</strong> 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.</p> <h3>More info on what I want:</h3> <p>I'm recently working on a task to localize the <strong>entire phone</strong> product with new languages(I mean, I'm <strong>not working on a specific application</strong>. This is why I need to add a new locale in the Settings). When I got the development phone, I found <strong>there are only</strong> several language entries available in the "Select Locale", such as "English", "French" and "Spain". So first of all, I need to <strong>add and display some new language entries</strong> to this list, such as "Japanese", "Chinese", "Korean".</p> <p>I have all the source code of Android platform and my own code, so I think this task can be done <strong>by modifying the source code or the resource files somewhere</strong>. Unfortunately, I don't know where the code and files are.</p> <p>The "<a href="http://developer.android.com/resources/tutorials/localization/index.html" rel="nofollow noreferrer">Hello, L10N</a>" tutorial shows a way to add a new locale from "Custom Locale" at run-time. But what I want is <strong>to add the new locales at build time</strong> so when the phone is started up, the new locales will be displayed in the "Select Locale" directly without any other actions.</p> <h3>What I have done:</h3> <p>I did a lot of research on the internet before I come here. Here is what I found:</p> <ol> <li><p>Sinkiru in Stackoverflow asked a question about what I am exactly looking for. See it <a href="https://stackoverflow.com/questions/4723892/how-can-i-remove-the-list-of-language-setting-in-the-source-level-of-android">here</a>. However, nobody else replied him. His own reply only tells where to query the CURRENT language setting, which is <strong>not</strong> what I want. I personally sent him an email for this question but haven't got his reply.</p></li> <li><p>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 <strong>NOT</strong> what I want.</p></li> <li><p>I searched a lot in the android-platform Google group(<a href="http://groups.google.com/group/android-platform" rel="nofollow noreferrer">http://groups.google.com/group/android-platform</a>). 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 <strong>not</strong> get what I want from them):</p> <ul> <li><p>"<a href="http://groups.google.com/group/android-platform/browse_thread/thread/92db0444363b5145/6a8d7e437568a0cb?lnk=gst&amp;q=language#6a8d7e437568a0cb" rel="nofollow noreferrer">OS localization</a>" - I'll talk more below.</p></li> <li><p>"<a href="http://groups.google.com/group/android-platform/browse_thread/thread/91bb05b119b005f5/1ba4ccc96f3cc6b7?lnk=gst&amp;q=language#1ba4ccc96f3cc6b7" rel="nofollow noreferrer">How to add new locale and it's associated font in android source</a>"</p></li> <li><p>"<a href="http://groups.google.com/group/android-platform/browse_thread/thread/5da2c5ced2f6b354/b92976ced202ae46?lnk=gst&amp;q=language#b92976ced202ae46" rel="nofollow noreferrer">How to add new L0cale</a>"</p></li> <li><p>"<a href="http://groups.google.com/group/android-platform/browse_thread/thread/99aa1e3b2fa6d65a/d40b84c2226c54c6?lnk=gst&amp;q=language#d40b84c2226c54c6" rel="nofollow noreferrer">Addition and Removal of language from Android Phone</a>"</p></li> <li><p>"<a href="http://groups.google.com/group/android-platform/browse_thread/thread/120bedaae22e27a/597121ac60739e16?lnk=gst&amp;q=language#597121ac60739e16" rel="nofollow noreferrer">Localization, committing new language</a>"</p></li> <li><p>"<a href="http://groups.google.com/group/android-platform/browse_thread/thread/acc429c5edaba695/fe419b1e214d0126?lnk=gst&amp;q=language#fe419b1e214d0126" rel="nofollow noreferrer">Additional languages support</a>"</p></li> <li><p>"<a href="http://groups.google.com/group/android-platform/browse_thread/thread/bda566cc2db1c326/97ae909f26f1b537?lnk=gst&amp;q=language#97ae909f26f1b537" rel="nofollow noreferrer">Localization - new locale - HELP</a>"</p></li> </ul></li> <li><p>Back to the entry "(a)" listed above. In the "OS localization" message thread, Dianne Hackborn, an Android framework engineer, said the following:</p></li> </ol> <blockquote> <p>"The settings app just shows you all of the locales that are available in the platform resources. <strong>Adding strings for a new locale should automatically have those shown in settings</strong>. You tell the <strong>build system which locale resources to include when it does the build</strong>... unfortunately I can't help you on that part, but maybe someone else can."</p> </blockquote> <p>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. <strong>I'm wondering if someone here has ever done the similar thing before?</strong> I'm going to give a try tomorrow.</p> <ol start="5"> <li><p>Last but not least, I searched in the official Android developer site. In the "Run and Test the Localized Application" of the "<a href="http://developer.android.com/resources/tutorials/localization/index.html" rel="nofollow noreferrer">Hello, L10N</a>" 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.</p></li> <li><p>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:</p> <p>String[] locales = getAssets().getLocales();</p></li> </ol> <p>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.</p> <p>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 <strong>GUESS</strong> 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 "<strong>mPackageGroups</strong>" is scanned through to retrieve all the available ResTable_config items. <strong>Thus I think all the available locales should be added into this mPackageGroups during the system started up.</strong> However, I lost in the code at last and couldn't find where the locales are added to the mPackageGroups.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload