Modify the default language and customize multiple languages in the android source code

Source: Internet
Author: User

This article focuses on the problem of Android customization in multiple languages, and summarizes its Customization Mechanism and implementation methods. If you want to learn more about the Customization Mechanism, read the first part of this article. If you only want to know How to customize it, refer to the second part.
Part 1 multi-language Customization Mechanism
1. icu4c Introduction

Icu4c (ICU for C, http://site.icu-project.org /)
It is the version of ICU on the C/C ++ platform. The ICU (international component for Unicode) is based on the "IBM Public License" and is studied in collaboration with open-source organizations, it is an open-source project that supports internationalization of software. Icu4c provides the powerful international development capability of the C/C ++ platform. Software developers can use icu4c to solve any international problems. According to the customs and language habits of different regions, to Format And parse numbers, currencies, times, dates, and messages, and convert, sort, search, and sort strings in case, icu4c provides powerful bidi algorithms and provides comprehensive support for bidi languages such as Arabic.

ICU was first developed by taligent, which is now merged into IBM? The Unicode research team of the company's global certification center, and the ICU was further developed by IBM and open-source organizations. The open-source organizations helped the ICU a lot.
At the beginning, the ICU was only available on the Java platform. Later, the ICU classes on this platform were incorporated into JDK developed by Sun and continuously improved in later JDK versions. The ICU on the C ++ and C platforms is transplanted from the icu on the Java platform. The transplanted version is called icu4c, to support international applications under the C/C ++ platforms. Icu4j is slightly different from icu4c, but because icu4c is open-source and closely follows the Unicode standard, Unicode standards supported by icu4c are always the latest. At the same time, because the release of icu4j on the Java platform needs to be bound with JDK, icu4c supports Unicode standard changes much faster than icu4j.

2. Android Language Pack

The Language Pack used by Android is icu4c. The location is external/icu4c. Android supports the following languages: 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 Zh.
Locale English
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. Custom Language

The custom language adds the required language to the product_locales field, for example, product_locales: = en_us zh_cn. Then, the system only has two languages: English and Chinese. Then the language selection process is performed 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
In build/CORE/makefile, select the first language from product_locales as the default language, as shown below:
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 ))"
Then, use the build/tool/buildinfo. Sh file to write the following section to the file build. Prop, as shown below:
Echo "Ro. Product. locale. Language = $ product_default_language"
Echo "Ro. Product. locale. region = $ product_default_region ".

Therefore, you can use either of the following methods to change the default language:

4.1 In the product_locales field, place the language to be selected first, for example, product_locales: = en_us zh_cn. The 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 \
Persist. SYS. Country = cn build. Prop file processing is in system/CORE/init/property_service.c.
Part 2 multi-language Customization
1. Implementation steps for multilingual Customization

1) Go to the build/target/product directory and modify the value of product_locales in the languages_full.mk or products file to customize the language, such as product_locales: = en_us zh_cn zh_tw en_GB fr_fr it_it de_es_es;

2) modify the full. mk file in the same directory
$ (Call inherit-product, build/target/product/languages_small | full. mk) statement to switch the files used;

3) re-compile.

2. steps for setting the default language
1) Go to the build/target/product directory and modify the product_property_overrides value of the file core. mk. For example, to change it to the default Chinese character, add
"\ Persist. SYS. Language = ZH \ persist. SYS. Country = cn". The added statement is as follows: product_property_overrides: = \

Ro.config.icationication_sound=onthehunt.ogg \

Ro.config.alarm_alertw.alarm_classic.ogg \ persist. SYS. Language = ZH \ persist. SYS. Country = Cn
2) re-compile.

3. fields related to multilingual customization and their files

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

No_fallback_font definition device/HTC/dream-sapphire/boardconfigcommon. mk

Call frameworks/base/data/fonts/Android. mk for no_fallback_font

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

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.