ADROID 2.1 架構解析 1 語言定制

lumit 14年前發布 | 4K 次閱讀 Android

1 語言定制

1.1 ICU4C

1.1.1 ICU4C簡介

ICU4C(ICU for Chttp://site.icu-project.org/)ICUC/C++平臺下的版本, ICU(International Component for Unicode)是基于"IBM公共許可證"的,與開源組織合作研究的, 用于支持軟件國際化的開源項目。ICU4C提供了C/C++平臺強大的國際化開發能力,軟件開發者幾乎可以使用ICU4C解決任何國際化的問題,根據各地的風俗和語言習慣,實現對數字、貨幣、時間、日期、和消息的格式化、解析,對字符串進行大小寫轉換、整理、搜索和排序等功能,必須一提的是,ICU4C提供了強大的BIDI算法,對阿拉伯語等BIDI語言提供了完善的支持。

  ICU首先是由Taligent公司開發的,Taligent公司現在被合并為IBM?公司全球化認證中心的Unicode研究組,然后ICUIBM和開源組織合作繼續開發,開源組織給與了ICU極大的幫助。

  開始ICU只有Java平臺的版本,后來這個平臺下的ICU類被吸納入SUN公司開發的JDK1.1,并在JDK以后的版本中不斷改進。C++C平臺下的ICU是由JAVA平臺下的ICU移植過來的,移植過的版本被稱為ICU4C,來支持這C/C++兩個平臺下的國際化應用。

ICU4CICU4C區別不大,但由于ICU4C是開源的,并且緊密跟進Unicode標準,ICU4C支持的Unicode標準總是最新的;同時,因為JAVA平臺的ICU4J的發布需要和JDK綁定,ICU4C支持Unicode標準改變的速度要比ICU4J快的多。

1.1.2 ANDROID語言包

Android 使用的語言包就是ICU4C,位置:external/icu4cAndroid支持的語言有:

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.

1.2 定制語言

PRODUCT_LOCALES字段里添加需要語言,如:

PRODUCT_LOCALES := en_US zh_CN

則系統里只有英語和漢語兩種語言。

然后語言的選擇處理是在external/icu4c/stubdata/Android.mk里進行的,如下:

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)

1.3 默認語言

默認語言的選擇實現是在build/core/Makefile里,從PRODUCT_LOCALES里選擇第一個語言作為默認語言,如下:

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))" \

 

然后通過build/tool/buildinfo.sh文件將如下段寫到文件build.prop,如下:

echo "ro.product.locale.language=$PRODUCT_DEFAULT_LANGUAGE"

echo "ro.product.locale.region=$PRODUCT_DEFAULT_REGION"

所以,要改變默認語言用下面兩種方法中的一種就行了:

1 PRODUCT_LOCALES字段里,將要選擇的語言放在第一位,如:

PRODUCT_LOCALES := en_US zh_CN

默認語言是英語

2

persist.sys.language persist.sys.country 里指定語言,如下:

PRODUCT_PROPERTY_OVERRIDES := \ 

    persist.sys.language=zh \

           persist.sys.country=CN

 

build.prop文件的處理是在system/core/init/property_service.c

 本文由用戶 lumit 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!