安卓系统语言添加
3个回答
展开全部
虽然Android从2.3开始已经支持50种以上的语言,但是不是每种语言都有字体可以显示。遇到一个新需求,有客户要求对hindi语言的支持。于是上网找了一些资料,发现网上介绍的大部分是如何替换默认字体,就是替换./frameworks/base/data/fonts/DroidSansFallback.ttf,但是替换完之后,中文就无法正常显示。其实只要有下面几个步骤,就可以实现新曾加一种语言的显示支持:
1. 需要有可以显示hindi语言的字体,我在网上下载了一个:DroidHindi.ttf
2. 需要修改的地方主要有
1) 将下载的字体文件拷贝到:./frameworks/base/data/fonts/
2) 修改./frameworks/base/data/fonts/Android.mk,将DroidHindi.ttf添加到copy_from:
copy_from := \
DroidSans.ttf \
DroidSans-Bold.ttf \
DroidSansArabic.ttf \
DroidSansHebrew.ttf \
DroidSansThai.ttf \
DroidHindi.ttf \
DroidSerif-Regular.ttf \
DroidSerif-Bold.ttf \
DroidSerif-Italic.ttf \
DroidSerif-BoldItalic.ttf \
DroidSansMono.ttf \
Clockopia.ttf
3) Hindi的语言代码是hi_IN,修改./device/qcom/common/common.mk,将hindi的语言代码加进去,这样在你的设置->语言和键盘->选择语言里面就可以看见hindi语言了:
PRODUCT_LOCALES := en_US en_GB es_ES es_US fr_FR zh_CN zh_TW hi_IN it_IT pt_PT ru_RU
4) 修改./external/skia/src/ports/SkFontHost_android.cpp,将DroidHindi.ttf加进去。网上介绍的很多方法都没有提到这一步,如果没有这一步的话,添加的语言是不生效的,显示的是乱码,因为android无法找到hindi语言可以显示的字体,还是会选择默认字体去显示。修改的地方为:
/* Fonts must be grouped by family, with the first font in a family having the
list of names (even if that list is empty), and the following members having
null for the list. The names list must be NULL-terminated
*/
static const FontInitRec gSystemFonts[] = {
{ "DroidSans.ttf", gSansNames },
{ "DroidSans-Bold.ttf", NULL },
{ "DroidSerif-Regular.ttf", gSerifNames },
{ "DroidSerif-Bold.ttf", NULL },
{ "DroidSerif-Italic.ttf", NULL },
{ "DroidSerif-BoldItalic.ttf", NULL },
{ "DroidSansMono.ttf", gMonoNames },
/* These are optional, and can be ignored if not found in the file system.
These are appended to gFallbackFonts[] as they are seen, so we list
them in the order we want them to be accessed by NextLogicalFont().
*/
{ "DroidSansArabic.ttf", gFBNames },
{ "DroidSansHebrew.ttf", gFBNames },
{ "DroidSansThai.ttf", gFBNames },
{ "DroidHindi.ttf", gFBNames }, // 新添加的语言
{ "MTLmr3m.ttf", gFBNames }, // Motoya Japanese Font
{ "MTLc3m.ttf", gFBNames }, // Motoya Japanese Font
{ "DroidSansJapanese.ttf", gFBNames },
{ "DroidSansFallback.ttf", gFBNames }
};
5) 去./build/target/product/full.mk看看系统选择的是哪个语言列表,我的是:
$(call inherit-product, build/target/product/languages_small.mk)
那我就去修改./build/target/product/languages_small.mk,若这里显示的是languages_full.mk,那么就修改./build/target/product/languages_full.mk文件,修改如下:
PRODUCT_LOCALES := en_US en_GB fr_FR hi_IN it_IT de_DE es_ES
3. 剩下的就是重新编译一下,然后flash到手机或模拟器上就可以了。
设置页面:
打开一个Hindi的网页,hindi语言可以正常显示了:
http://www.cnblogs.com/melaniedeng/archive/2012/02/15/2353382.html
1. 需要有可以显示hindi语言的字体,我在网上下载了一个:DroidHindi.ttf
2. 需要修改的地方主要有
1) 将下载的字体文件拷贝到:./frameworks/base/data/fonts/
2) 修改./frameworks/base/data/fonts/Android.mk,将DroidHindi.ttf添加到copy_from:
copy_from := \
DroidSans.ttf \
DroidSans-Bold.ttf \
DroidSansArabic.ttf \
DroidSansHebrew.ttf \
DroidSansThai.ttf \
DroidHindi.ttf \
DroidSerif-Regular.ttf \
DroidSerif-Bold.ttf \
DroidSerif-Italic.ttf \
DroidSerif-BoldItalic.ttf \
DroidSansMono.ttf \
Clockopia.ttf
3) Hindi的语言代码是hi_IN,修改./device/qcom/common/common.mk,将hindi的语言代码加进去,这样在你的设置->语言和键盘->选择语言里面就可以看见hindi语言了:
PRODUCT_LOCALES := en_US en_GB es_ES es_US fr_FR zh_CN zh_TW hi_IN it_IT pt_PT ru_RU
4) 修改./external/skia/src/ports/SkFontHost_android.cpp,将DroidHindi.ttf加进去。网上介绍的很多方法都没有提到这一步,如果没有这一步的话,添加的语言是不生效的,显示的是乱码,因为android无法找到hindi语言可以显示的字体,还是会选择默认字体去显示。修改的地方为:
/* Fonts must be grouped by family, with the first font in a family having the
list of names (even if that list is empty), and the following members having
null for the list. The names list must be NULL-terminated
*/
static const FontInitRec gSystemFonts[] = {
{ "DroidSans.ttf", gSansNames },
{ "DroidSans-Bold.ttf", NULL },
{ "DroidSerif-Regular.ttf", gSerifNames },
{ "DroidSerif-Bold.ttf", NULL },
{ "DroidSerif-Italic.ttf", NULL },
{ "DroidSerif-BoldItalic.ttf", NULL },
{ "DroidSansMono.ttf", gMonoNames },
/* These are optional, and can be ignored if not found in the file system.
These are appended to gFallbackFonts[] as they are seen, so we list
them in the order we want them to be accessed by NextLogicalFont().
*/
{ "DroidSansArabic.ttf", gFBNames },
{ "DroidSansHebrew.ttf", gFBNames },
{ "DroidSansThai.ttf", gFBNames },
{ "DroidHindi.ttf", gFBNames }, // 新添加的语言
{ "MTLmr3m.ttf", gFBNames }, // Motoya Japanese Font
{ "MTLc3m.ttf", gFBNames }, // Motoya Japanese Font
{ "DroidSansJapanese.ttf", gFBNames },
{ "DroidSansFallback.ttf", gFBNames }
};
5) 去./build/target/product/full.mk看看系统选择的是哪个语言列表,我的是:
$(call inherit-product, build/target/product/languages_small.mk)
那我就去修改./build/target/product/languages_small.mk,若这里显示的是languages_full.mk,那么就修改./build/target/product/languages_full.mk文件,修改如下:
PRODUCT_LOCALES := en_US en_GB fr_FR hi_IN it_IT de_DE es_ES
3. 剩下的就是重新编译一下,然后flash到手机或模拟器上就可以了。
设置页面:
打开一个Hindi的网页,hindi语言可以正常显示了:
http://www.cnblogs.com/melaniedeng/archive/2012/02/15/2353382.html
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询