android 修改系统默认语言

Android系统原版默认的语言为英文,而我们定制系统可能需要用户一开机就是简体中文。
我们可以通过修改系统属性来达到默认语言的作用。
这里有两种方法,需要的可以借鉴下:
1、在init.rc或者在其他的开机初始化文件如:default.prop中加入如下设置系统属性的代码:
[html] view plaincopy
1. [persist.sys.language]: [zh] 
2. [persist.sys.country]: [CN] 
3. [persist.sys.localevar]: [] 
4. [persist.sys.timezone]: [Asia/Shanghai] 
5. [ro.product.locale.language]: [zh] 
6. [ro.product.locale.region]: [CN] 

2、编译的时候,通过指明编译参数为简体中文,这样编译传统就会编译出来的系统属性文件,在
系统初始化的时候将会把上面的属性给进行正确的初始化,例如:
make PRODUCT-machineID-eng-zh_CN

其他相关资料:
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++两个平台下的国际化应用。 ICU4J和ICU4C区别不大,但由于ICU4C是开源的,并且紧密跟进Unicode标准,ICU4C支持的Unicode标准总是最新的;同时,因 为JAVA平台的ICU4J的发布需要和JDK绑定,ICU4C支持Unicode标准改变的速度要比ICU4J快的多。
2、 ANDROID语言包
Android 使用的语言包就是ICU4C,位置:external/icu4c。Android支持的语言有: Locale CANADA
[html] view plaincopy
1. Locale constant for en_CA. 
2. Locale CANADA_FRENCH 
3. Locale constant for fr_CA. 
4. Locale CHINA 
5. Locale constant for zh_CN. 
6. Locale CHINESE 
7. Locale constant for zh. 
8. Locale ENGLISH 
9. Locale constant for en. 
10. Locale FRANCE 
11. Locale constant for fr_FR. 
12. Locale FRENCH 
13. Locale constant for fr. 
14. Locale GERMAN 
15. Locale constant for de. 
16. Locale GERMANY 
17. Locale constant for de_DE. 
18. Locale ITALIAN 
19. Locale constant for it. 
20. Locale ITALY 
21. Locale constant for it_IT. 
22. Locale JAPAN 
23. Locale constant for ja_JP. 
24. Locale JAPANESE 
25. Locale constant for ja. 
26. Locale KOREA 
27. Locale constant for ko_KR. 
28. Locale KOREAN 
29. Locale constant for ko. 
30. Locale PRC 
31. Locale constant for zh_CN. 
32. Locale SIMPLIFIED_CHINESE 
33. Locale constant for zh_CN. 
34. Locale TAIWAN 
35. Locale constant for zh_TW. 
36. Locale TRADITIONAL_CHINESE 
37. Locale constant for zh_TW. 
38. Locale UK 
39. Locale constant for en_GB. 
40. Locale US 
41. Locale constant for en_US. 

3、定制语言
定制语言在PRODUCT_LOCALES字段里添加需要语言,如: PRODUCT_LOCALES := en_US zh_CN,则系统里只有英语和汉语两种语言。然后语言的选择处理是在external/icu4c/stubdata/Android.mk里进行的, 如下:
[html] view plaincopy
1. config := $(word 1, \ $(if $(findstring ar,$(PRODUCT_LOCALES)),large) \ 
2. $(if $(findstring da,$(PRODUCT_LOCALES)),large) \ 
3. $(if $(findstring el,$(PRODUCT_LOCALES)),large) \ 
4. $(if $(findstring fi,$(PRODUCT_LOCALES)),large) \ 
5. $(if $(findstring he,$(PRODUCT_LOCALES)),large) \ 
6. $(if $(findstring hr,$(PRODUCT_LOCALES)),large) \ 
7. $(if $(findstring hu,$(PRODUCT_LOCALES)),large) \ 
8. $(if $(findstring id,$(PRODUCT_LOCALES)),large) \ 
9. $(if $(findstring ko,$(PRODUCT_LOCALES)),large) \ 
10. $(if $(findstring nb,$(PRODUCT_LOCALES)),large) \ 
11. $(if $(findstring pt,$(PRODUCT_LOCALES)),large) \ 
12. $(if $(findstring ro,$(PRODUCT_LOCALES)),large) \ 
13. $(if $(findstring ru,$(PRODUCT_LOCALES)),large) \ 
14. $(if $(findstring sk,$(PRODUCT_LOCALES)),large) \ 
15. $(if $(findstring sr,$(PRODUCT_LOCALES)),large) \ 
16. $(if $(findstring sv,$(PRODUCT_LOCALES)),large) \ 
17. $(if $(findstring th,$(PRODUCT_LOCALES)),large) \ 
18. $(if $(findstring tr,$(PRODUCT_LOCALES)),large) \ 
19. $(if $(findstring uk,$(PRODUCT_LOCALES)),large) \ 
20. $(if $(findstring zh,$(PRODUCT_LOCALES)),large) \ 
21. $(if $(findstring ja,$(PRODUCT_LOCALES)),us-japan) \ 
22. $(if $(findstring it,$(PRODUCT_LOCALES)),us-euro) \ 
23. $(if $(findstring pl,$(PRODUCT_LOCALES)),us-euro) \ 
24. $(if $(findstring cs,$(PRODUCT_LOCALES)),default) \ 
25. $(if $(findstring de,$(PRODUCT_LOCALES)),default) \ 
26. $(if $(findstring fr,$(PRODUCT_LOCALES)),default) \ 
27. $(if $(findstring nl,$(PRODUCT_LOCALES)),default) \ 
28. us) 

4、默认语言
默认语言的选择实现是在build/core/Makefile里,从PRODUCT_LOCALES里选择第一个语言作为默认语言,如下:
[html] view plaincopy
1. define default-locale $(subst _, , $(firstword $(1))) 
2. endef 
3. # Selects the first locale in the list given as the argument 
4. # and returns the language (or the region) 
5. define default-locale-language $(word 2, 2, $(call default-locale, $(1))) 
6. endef 
7. define default-locale-region $(word 3, 3, $(call default-locale, $(1))) 
8. Endef ... PRODUCT_DEFAULT_LANGUAGE="$(call default-locale-language,$(PRODUCT_LOCALES))" \ 
9. PRODUCT_DEFAULT_REGION="$(call default-locale-region,$(PRODUCT_LOCALES))" 


然后通过build/tool/buildinfo.sh文件将如下段写到文件build.prop,如下:
[html] view plaincopy
1. echo "ro.product.locale.language=$PRODUCT_DEFAULT_LANGUAGE" 
2. echo "ro.product.locale.region=$PRODUCT_DEFAULT_REGION" 。 

因此,要改变默认语言用下面两种方法中的一种就行了:
4.1、在PRODUCT_LOCALES字段里,将要选择的语言放在第一位,如: PRODUCT_LOCALES := en_US zh_CN 默认语言是英语;
4.2、在persist.sys.language 和persist.sys.country 里指定语言,如下:
[html] view plaincopy
1. PRODUCT_PROPERTY_OVERRIDES := \ 
2. persist.sys.language=zh \ 
3. persist.sys.country=CN  

PRODUCT_LOCALES 环境变量在什么地方,最后在
build/target/product/sdk.mk 里面找到了这个变量,然后修改里面的
PRODUCT_LOCALES 变量
PRODUCT_LOCALES := \
en_US \
zh_CN \
zh_TW
编译,并烧录文件, 发现系统语言版本还是没变化。再认真查看里面的文件,还是找不到
最后在build/target/product/core.mk 把如下
PRODUCT_LOCALES := \
en_US \
zh_CN \
zh_TW
添加到这里,重新编译,烧录发现成功了~!不知道为什么,哎!!!

From:http://blog.csdn.net/bmj/article/details/7659616

猜你喜欢

转载自sunj.iteye.com/blog/1989415