ADROID 2.1 架构解析 语言定制

来源:互联网 发布:mac专柜地址 编辑:程序博客网 时间:2024/05/01 11:13

1 语言定制1.1 ICU4C1.1.1 ICU4C简介ICU4C(ICU for C,http://site.icu-project.org/)是ICU在C/C++平台下的版本, ICU(International Component for Unicode)是基于"IBM公共许可证"的,与开源组织合作研究的, 用于支持软件国际化的开源项目。ICU4C提供了C/C++平台强大的国际化开发能力,软件开发者几乎可以使用ICU4C解决任何国际化的问题,根据各地的风俗和语言习惯,实现对数字、货币、时间、日期、和消息的格式化、解析,对字符串进行大小写转换、整理、搜索和排序等功能,必须一提的是,ICU4C提供了强大的BIDI算法,对阿拉伯语等BIDI语言提供了完善的支持。  ICU首先是由Taligent公司开发的,Taligent公司现在被合并为IBM?公司全球化认证中心的Unicode研究组,然后ICU由IBM和开源组织合作继续开发,开源组织给与了ICU极大的帮助。  开始ICU只有Java平台的版本,后来这个平台下的ICU类被吸纳入SUN公司开发的JDK1.1,并在JDK以后的版本中不断改进。C++和C平台下的ICU是由JAVA平台下的ICU移植过来的,移植过的版本被称为ICU4C,来支持这C/C++两个平台下的国际化应用。ICU4C和ICU4C区别不大,但由于ICU4C是开源的,并且紧密跟进Unicode标准,ICU4C支持的Unicode标准总是最新的;同时,因为JAVA平台的ICU4J的发布需要和JDK绑定,ICU4C支持Unicode标准改变的速度要比ICU4J快的多。1.1.2 ANDROID语言包Android 使用的语言包就是ICU4C,位置:external/icu4c。Android支持的语言有: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)))endefdefine 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。

原创粉丝点击