How to add a new language for Android

Source: Internet
Author: User

Although Android has supported more than 50 languages since 2.3, not all languages have fonts to display. A customer needs to support hindi in a new requirement. So I found some information on the Internet and found that most of the information on the Internet is how to replace the default font, that is, replace. /frameworks/base/data/fonts/DroidSansFallback. ttf. However, after the replacement, Chinese characters cannot be displayed normally.
In fact, as long as there are several steps below, we can implement the display support of the new once-plus language:
1. You need a font that can display the hindi language. I downloaded DroidHindi. ttf online.
2. The main areas to be modified are:
1) copy the downloaded font file to:./frameworks/base/data/fonts/
2) Modify./frameworks/base/data/fonts/Android. mk and add DroidHindi. ttf to copy_from:
Copy codeThe Code is as follows: 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) the Hindi language code is hi_IN. modify it. /device/qcom/common. mk: add the hindi language code so that you can see the hindi language in your Settings> language and keyboard> Select language:
Copy codeThe Code is as follows: 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) Modify./external/skia/src/ports/SkFontHost_android.cpp and add DroidHindi. ttf. This step is not mentioned in many methods introduced on the Internet. Without this step, the added language does not take effect and garbled characters are displayed, because android cannot find the font that the hindi language can display, it will still select the default font to display. The modification is as follows:Copy codeThe Code is as follows:/* Fonts must be grouped by family, with the first font in a family having
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}, // new language
{"MTLmr3m. ttf", gFBNames}, // Motoya Japanese Font
{"MTLc3m. ttf", gFBNames}, // Motoya Japanese Font
{"DroidSansJapanese. ttf", gFBNames },
{"DroidSansFallback. ttf", gFBNames}
};

5) Go to./build/target/product/full. mk to see which language list is selected by the system. Mine is:
$ (Call inherit-product, build/target/product/languages_small.mk)
Then I will modify./build/target/product/languages_small.mk. If languages_full.mk is displayed here, modify the./build/target/product/languages_full.mk file and modify it as follows:
PRODUCT_LOCALES: = en_US en_GB fr_FR hi_IN it_IT de_DE es_ES

3. The rest is to recompile it and then flash it to the mobile phone or simulator.
Settings page:

Open a Hindi webpage, And the hindi language is displayed normally:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.