• 为Android添加一门新语言


    虽然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语言可以正常显示了:

  • 相关阅读:
    haproxy报错解决
    haproxy安装
    gitlab配置webhook报错解决
    git_push报错
    DNS配置
    centos7 选定默认启动内核,及删除无用内核
    ansible安装、配置ssh、hosts、测试连接
    公司手机打卡app时间和百度时间差30秒解决
    所有编辑语言的共性内容元素
    php使用正则函数使用详解
  • 原文地址:https://www.cnblogs.com/melaniedeng/p/2353382.html
Copyright © 2020-2023  润新知