以下以新增墨西哥西班牙語(es_MX)為例,說明在 Android 原始碼中加入一門新語言的完整步驟,涵蓋 ICU 資料、編譯、字串資源與產品設定等環節。
在 external/icu4c/data/locales/ 底下新增 es_MX.txt,內容如下:
es_MX{
Currencies{
MXN{
"$",
"peso mexicano",
}
}
NumberElements{
".",
",",
";",
"%",
"0",
"#",
"-",
"E",
"\u2030",
"\u221e",
"NaN",
"+",
}
PaperSize:intvector{
279,
216,
}
Version{"1.53"}
calendar{
gregorian{
DateTimeElements:intvector{
1,
4,
}
}
}
}
在 icu4c 底下執行 mkdir icuBuild,接著 cd external/icu4c/icuBuild 並執行 ../runConfigureICU Linux。
執行 make -j 2 進行編譯。
把 icu4c/icuBuild/data/out/tmp/icudt42l.dat 複製到 icu4c/stubdata/ 下面,替換原本的 icudt42l-all.dat。
在檔案中增加 es_MX.res 與 coll/es_MX.res。
執行 ./icu_dat_generator.py 4.2。這裡可能會出錯,解法是先把 icu4c/icuBuild/bin/ 底下的 gencnval、genrb、icupkg、makeconv 複製到 prebuilt/linux-x86/icu-4.2/ 底下並替換原檔,再執行該命令即可:
cp -rf gencnval genrb icupkg makeconv ../../../../prebuilt/linux-x86/icu-4.2/
在 framework/base/core/res/res/ 底下新建 values-es-rMX/ 資料夾,把 donottranslate-cldr.xml 與 strings.xml 兩個檔案加入。
修改 vender/sprd/product/sprdroid_base.mk 中 PRODUCT_LOCALES 的值,增加 es_MX。
更多 Android 相關資訊見 Android 專題頁面 https://www.linuxidc.com/topicnews.aspx?tid=11