Android Language Customization

Source: Internet
Author: User
Tags locale

This article is mainly to the Android custom multi-language question to carry on the thorough research, summarizes its customization mechanism and its concrete realization method. If you want to learn more about its customization mechanism, read the first part of this article, and if you just want to know how to customize it, please refer to the second section.


The first part of the multi-lingual customization mechanism


1, icu4c Introduction

ICU4C (ICU for C, http://site.icu-project.org/) is a version of the ICU under the C + + platform, and the ICU (International Component for Unicode) is based on "IBM Public License", Open source projects in collaboration with open source organizations to support the internationalization of software. ICU4C provides a strong international development capability of the C + + platform, software developers can use ICU4C to solve any international problems, according to local customs and language habits, to achieve the number, currency, time, date, and message formatting, parsing, the case of the string conversion, collation, Search and sorting functions, it must be mentioned that ICU4C provides a powerful Bidi algorithm, the Arabic language and other Bidi to provide perfect support.

The ICU was first developed by Taligent, and the Taligent company is now incorporated into the Unicode research group of IBM's Global Certification Center, which is then co-developed by IBM and the Open source organization, which is a great help to the ICU.
Beginning the ICU only version of the Java platform, later the ICU class under this platform was sucked into the JDK1.1 developed by Sun, and was continuously improved in later versions of the JDK. ICU under the C + + and C platforms is ported from ICU under the Java platform, and the migrated version is called ICU4C to support the internationalization of this two-C + + platform. Icu4j and icu4c differ little, but because icu4c is open source and closely follows the Unicode standard, ICU4C supports Unicode standards that are always up-to-date, and because the Java platform's icu4j release needs to be tied to the JDK, ICU4C supports Unicode standards to change much faster than icu4j.

2. Android Language Pack

The language pack that Android uses is icu4c, location: external/icu4c. The languages supported by Android are: Locale CANADA
Locale constant for En_ca.
Locale Canada_french
Locale constant for Fr_ca.
Locale China
Locale constant for ZH_CN.
Locale Chinese
Locale constant for en.
Locale 中文版
Locale constant for en.
Locale FRANCE
Locale constant for FR_FR.
Locale FRENCH
Locale constant for Fr.
Locale GERMAN
Locale constant for DE.
Locale Germany
Locale constant for De_de.
Locale Italian
Locale constant for it.
Locale ITALY
Locale constant for IT_IT.
Locale JAPAN
Locale constant for JA_JP.
Locale Japanese
Locale constant for JA.
Locale KOREA
Locale constant for KO_KR.
Locale KOREAN
Locale constant for KO.
Locale PRC
Locale constant for ZH_CN.
Locale Simplified_chinese
Locale constant for ZH_CN.
Locale TAIWAN
Locale constant for ZH_TW.
Locale Traditional_chinese
Locale constant for ZH_TW.
Locale UK
Locale constant for EN_GB.
Locale US
Locale constant for en_US.

3. Customized language

Custom language in the Product_locales field to add the required language, such as: product_locales: = en_US ZH_CN, the system is only English and Chinese language. Then the choice of language processing is carried out in External/icu4c/stubdata/android.mk, as follows:
Config: = $ (Word 1,/$ (if $ (findstring ar,$ (product_locales)), Large)/
$ (if $ (findstring da,$ (product_locales)), Large)/
$ (if $ (findstring el,$ (product_locales)), Large)/
$ (if $ (findstring fi,$ (product_locales)), Large)/
$ (if $ (findstring he,$ (product_locales)), Large)/
$ (if $ (findstring hr,$ (product_locales)), Large)/
$ (if $ (findstring hu,$ (product_locales)), Large)/
$ (if $ (findstring id,$ (product_locales)), Large)/
$ (if $ (findstring ko,$ (product_locales)), Large)/
$ (if $ (findstring nb,$ (product_locales)), Large)/
$ (if $ (findstring pt,$ (product_locales)), Large)/
$ (if $ (findstring ro,$ (product_locales)), Large)/
$ (if $ (findstring ru,$ (product_locales)), Large)/
$ (if $ (findstring sk,$ (product_locales)), Large)/
$ (if $ (findstring sr,$ (product_locales)), Large)/
$ (if $ (findstring sv,$ (product_locales)), Large)/
$ (if $ (findstring th,$ (product_locales)), Large)/
$ (if $ (findstring tr,$ (product_locales)), Large)/
$ (if $ (findstring uk,$ (product_locales)), Large)/
$ (if $ (findstring zh,$ (product_locales)), Large)/
$ (if $ (findstring ja,$ (product_locales)), Us-japan)/
$ (if $ (findstring it,$ (product_locales)), Us-euro)/
$ (if $ (findstring pl,$ (product_locales)), Us-euro)/
$ (if $ (findstring cs,$ (product_locales)), default)/
$ (if $ (findstring de,$ (product_locales)), default)/
$ (if $ (findstring fr,$ (product_locales)), default)/
$ (if $ (findstring nl,$ (product_locales)), default)/
us

4. Default language
The default language selection implementation is in Build/core/makefile, select the first language from the Product_locales as the default language, as follows:
Define Default-locale $ (subst _, $ (FirstWord $ (1)))
Endef
# selects the first locale in the list given as the argument
# and returns the language (or the region)
Define Default-locale-language $ (Word 2, 2, $ (call Default-locale, $ (1)))
Endef
Define Default-locale-region $ (Word 3, 3, $ (call Default-locale, $ (1)))
Endef ... Product_default_language= "$ (call default-locale-language,$ (product_locales))"/
Product_default_region= "$ (call default-locale-region,$ (product_locales))"
The following paragraph is then written to the file Build.prop via the build/tool/buildinfo.sh file, as follows:
echo "Ro.product.locale.language= $PRODUCT _default_language"
echo "ro.product.locale.region= $PRODUCT _default_region".

Therefore, to change the default language, use one of the following two methods:

4.1, in the Product_locales field, the language to be selected in the first place, such as: product_locales: = en_US zh_cn default language is English;
4.2. Specify the language in Persist.sys.language and Persist.sys.country as follows: product_property_overrides: =/
Persist.sys.language=zh/
The PERSIST.SYS.COUNTRY=CN build.prop file is processed in system/core/init/property_service.c.


The second part of the multi-language customization method


1, multi-language customization to achieve the steps

1) Enter the Build/target/product directory, in the languages_full.mk or languages_small.mk file, modify the value of the Product_locales, to customize the language, such as Product_ LOCALES: = en_US zh_cn zh_tw en_gb fr_fr it_it de_de es_es;

2) Under the same directory, modify the Full.mk file
$ (call inherit-product, BUILD/TARGET/PRODUCT/LANGUAGES_SMALL|FULL.MK) statement to switch the file used;

3) recompile.

You can also modify Frameworks/base/core/java/com/android/internal/app/localepicker.java


2, set the default language implementation steps
1) Enter the Build/target/product directory, modify the file core.mk product_property_overrides value, for example, to modify the default Chinese, then increase
"/PERSIST.SYS.LANGUAGE=ZH/PERSIST.SYS.COUNTRY=CN", added after the statement such as product_property_overrides: =/

Ro.config.notification_sound=onthehunt.ogg/

RO.CONFIG.ALARM_ALERT=ALARM_CLASSIC.OGG/PERSIST.SYS.LANGUAGE=ZH/PERSIST.SYS.COUNTRY=CN
2) recompile.

3. Fields related to multi-language customization and the files in which they reside

Previous_build_config out/target/product/dream/previous_build_config.mk

Definition of No_fallback_font device/htc/dream-sapphire/boardconfigcommon.mk

No_fallback_font Call Frameworks/base/data/fonts/android.mk

Extra_locales custom_locales nodpi mdpi hdpi build/core/product_config.mk

Product_property_overrides build/target/product
Build.prop Out/target/product/generic/system

Android Language Customization

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.