最近几个项目需要添加缅甸语,借助网络资源,同时结合自身实践,成功添加缅甸语,现分享经验如下。
一. 前期工作;
- 准备Myanmar字库,下载地址:http://www.myordbok.com/myanmar-fonts/ ,或者http://download.csdn.net/detail/marine8888/5813057 。
- 准备系统字串的缅甸文翻译,提供一份供各位测试缅甸语的Settings模块的字串,下载地址:http://download.csdn.net/detail/marine8888/5812889
二.修改icu模块
- 添加行coll/my.res
- 添加行 coll/my_MM.res
- 添加行curr/my.res
- 添加行lang/my.res
- 添加行region/my.res
- 添加行zone/my.res
- 添加行my.res
- 添加行my_MM.res
ICU_PREBUILT_DIR = os.path.join(os.environ.get("ANDROID_EABI_TOOLCHAIN"),
"..", "..", "..", "icu-%s.%s" % (icu_version[0], icu_version[1]))
ICU_PREBUILT_DIR = os.path.join(os.environ.get("ANDROID_BUILD_TOP"),
"prebuilt", "linux-x86","icu-%s.%s" % (icu_version[0], icu_version[1]))
三. 添加缅甸语字库文件到系统
1.添加文件夹,openfont,目录树如下:
├── Android.mk
├── CleanSpec.mk
├── fonts.mk
├── NOTICE
└── padauk-ttf
├── COPYRIGHT
├── OFL.txt
└── Padauk.ttf
2 directories, 10 files
LOCAL_PATH := $(call my-dir) ifneq ($(SMALLER_FONT_FOOTPRINT),true) ifneq (,$(filter my_MM,$(PRODUCT_LOCALES)))
include $(CLEAR_VARS)
LOCAL_MODULE := Padauk.ttf
LOCAL_SRC_FILES := padauk-ttf/$(LOCAL_MODULE)
LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_PATH := $(TARGET_OUT)/fonts
include $(BUILD_PREBUILT)
endif endif
fonts.mk内容如下:
PRODUCT_PACKAGES := \
Padauk.ttf
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/ETC/Mondulkiri.ttf_intermediates)
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/fonts/Mondulkiri.ttf )
2. 修改frameworks/base/data/fonts/Android.mk,增加如下行:
# Use the following to include the added fonts.
include $(call all-makefiles-under,$(LOCAL_PATH))
使得可以编译到openfont文件夹。
3.修改frameworks/base/data/fonts/fallback_fonts.xml,增加如下内容:
<family>
<fileset>
<file>Padauk.ttf</file>
</fileset>
</family>
4. 修改build/target/product/common.mk,增加如下内容:
ifneq (,$(filter my_MM,$(MTK_PRODUCT_LOCALES)))
PRODUCT_PACKAGES += Padauk.ttf
endif
5. 修改mediatek/config/ztesz75_cu_ics/ProjectConfig.mk,添加缅甸语的国家码my_MM到MTK_PRODUCT_LOCALES中,如下所示:
MTK_PRODUCT_LOCALES = en_US hi_IN in_ID es_ES ru_RU pt_BR fa_IR fr_FR de_DE tr_TR it_IT ms_MY vi_VN ar_EG th_TH pt_PT my_MM nl_NL zh_CN zh_TW mdpi hdpi
另, MTK_PRODUCT_LOCALES的第一个字段是系统的默认语言,也就是出厂语言,如果要把缅甸语设置成默认语言,只需将my_MM放在第一个位置即可。
四. 添加缅甸语字串
从网络上了解到另外一种添加语言的方法,有参考的价值,但是没有验证过,有兴趣的朋友可以参考下,链接如下:http://androidandsandu.blogspot.com/2011/12/how-to-add-indian-languages-to-android.html。
可能有些朋友访问不了外网,现贴原文如下:
How to add Indian Languages to Android ICS (4.0.3)
The AOSP code supports rendering of three Indian languages in Web-kit. (Devanagari, Tamil, and Bengali).
I just added support for the other Indian languages as well. Tested it on my Nexus-S device
Prerequisites :
- ICS (4.0.3) AOSP source code.
- Nexus -s Device
Follow these instructions:
1) Download the "Binary" file of the Indian language from
this link.
Ex: lohit-kananda-ttf-2.5.0.tar.gz
2) Untar the downloaded file and Copy the extracted folder into
external/lohit-fonts directory
Ex: lohit-kannada-ttf-2.5.0
3) Rename the folder name to lohit-kannada-ttf
4) Modify the Android.mk file which is present in external\lohit-fonts directory
ifneq ($(SMALLER_FONT_FOOTPRINT),true)
extra_lohit_fonts := Lohit-Bengali.ttf Lohit-Tamil.ttf Lohit-Kannada.ttf
endif
include $(CLEAR_VARS)
LOCAL_MODULE := Lohit-Kannada.ttf
LOCAL_SRC_FILES := lohit-kannada-ttf/$(LOCAL_MODULE)
LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_PATH := $(TARGET_OUT)/fonts
include $(BUILD_PREBUILT)
5) Modify the FontAndroid.cpp file (external/webkit/source/webcore/platform/graphics/android)
a) Add an language entry to CustomScript enum
enum CustomScript {
Bengali,
Devanagari,
Kannada,
.......
};
b) Add the ttf file path to the TextRunWalker Paths
const char* TextRunWalker::paths[] = {
"/system/fonts/Lohit-Bengali.ttf",
"/system/fonts/Lohit-Devanagari.ttf",
"/system/fonts/Lohit-Kannada.ttf",
........
};
c) Now setup the Font for Script Run
TextRunWalker::setupFontForScriptRun()
{
case HB_Script_Kannada:
complexPlatformData = setupComplexFont(Kannada, platformData);
break;
}
6) Add the *.ttf file in Fallback_fonts.xml
(frameworks\base\data\fonts)