From 6bb3556ff7b24a5a38d7cc4276017bda3a9a4bba Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 8 Apr 2014 17:01:13 +0900 Subject: [PATCH] Use locale to look up KeyboardTextsTable Change-Id: I1e05c7fdbb757efef0e9407dc25482ef1115e49a --- .../keyboard/internal/KeyboardTextsSet.java | 3 +- .../keyboard/internal/KeyboardTextsTable.java | 386 +++++++++--------- .../keyboard/internal/KeyboardTextsTable.tmpl | 50 ++- .../inputmethod/keyboard/tools/JarUtils.java | 22 +- .../keyboard/tools/LocaleUtils.java | 17 +- .../keyboard/tools/MoreKeysResources.java | 49 ++- .../keyboard/tools/StringResourceMap.java | 8 +- 7 files changed, 273 insertions(+), 262 deletions(-) diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java index 56acdde8d..0047aa4a1 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java @@ -41,8 +41,7 @@ public final class KeyboardTextsSet { private HashMap mResourceNameToTextsMap = CollectionUtils.newHashMap(); public void setLocale(final Locale locale, final Context context) { - final String language = locale.getLanguage(); - mTextsTable = KeyboardTextsTable.getTextsTable(language); + mTextsTable = KeyboardTextsTable.getTextsTable(locale); final Resources res = context.getResources(); final int referenceId = context.getApplicationInfo().labelRes; final String resourcePackageName = res.getResourcePackageName(referenceId); diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsTable.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsTable.java index 17611c6cc..1bd98332f 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsTable.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsTable.java @@ -19,6 +19,7 @@ package com.android.inputmethod.keyboard.internal; import com.android.inputmethod.latin.utils.CollectionUtils; import java.util.HashMap; +import java.util.Locale; /** * !!!!! DO NOT EDIT THIS FILE !!!!! @@ -44,19 +45,19 @@ import java.util.HashMap; public final class KeyboardTextsTable { // Name to index map. private static final HashMap sNameToIndexesMap = CollectionUtils.newHashMap(); - // Language to texts table map. - private static final HashMap sLanguageToTextsTableMap = + // Locale to texts table map. + private static final HashMap sLocaleToTextsTableMap = CollectionUtils.newHashMap(); // TODO: Remove this variable after debugging. - // Texts table to language maps. - private static final HashMap sTextsTableToLanguageMap = + // Texts table to locale maps. + private static final HashMap sTextsTableToLocaleMap = CollectionUtils.newHashMap(); public static String getText(final String name, final String[] textsTable) { final Integer indexObj = sNameToIndexesMap.get(name); if (indexObj == null) { - throw new RuntimeException("Unknown text name=" + name + " language=" - + sTextsTableToLanguageMap.get(textsTable)); + throw new RuntimeException("Unknown text name=" + name + " locale=" + + sTextsTableToLocaleMap.get(textsTable)); } final int index = indexObj; final String text = (index < textsTable.length) ? textsTable[index] : null; @@ -64,17 +65,24 @@ public final class KeyboardTextsTable { return text; } // Sanity check. - if (index >= 0 && index < LANGUAGE_DEFAULT.length) { - return LANGUAGE_DEFAULT[index]; + if (index >= 0 && index < TEXTS_DEFAULT.length) { + return TEXTS_DEFAULT[index]; } // Throw exception for debugging purpose. throw new RuntimeException("Illegal index=" + index + " for name=" + name - + " language=" + sTextsTableToLanguageMap.get(textsTable)); + + " locale=" + sTextsTableToLocaleMap.get(textsTable)); } - public static String[] getTextsTable(final String language) { - final String[] textsTable = sLanguageToTextsTableMap.get(language); - return textsTable != null ? textsTable : LANGUAGE_DEFAULT; + public static String[] getTextsTable(final Locale locale) { + final String localeKey = locale.toString(); + if (sLocaleToTextsTableMap.containsKey(localeKey)) { + return sLocaleToTextsTableMap.get(localeKey); + } + final String languageKey = locale.getLanguage(); + if (sLocaleToTextsTableMap.containsKey(languageKey)) { + return sLocaleToTextsTableMap.get(languageKey); + } + return TEXTS_DEFAULT; } private static final String[] NAMES = { @@ -252,7 +260,7 @@ public final class KeyboardTextsTable { private static final String EMPTY = ""; /* Default texts */ - private static final String[] LANGUAGE_DEFAULT = { + private static final String[] TEXTS_DEFAULT = { /* morekeys_a ~ */ EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, /* ~ morekeys_c */ @@ -457,8 +465,8 @@ public final class KeyboardTextsTable { /* keyspec_emoji_key */ "!icon/emoji_key|!code/key_emoji", }; - /* Language af: Afrikaans */ - private static final String[] LANGUAGE_af = { + /* Locale af: Afrikaans */ + private static final String[] TEXTS_af = { // This is the same as Dutch except more keys of y and demoting vowels with diaeresis. // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX @@ -513,8 +521,8 @@ public final class KeyboardTextsTable { /* morekeys_y */ "\u00FD,\u0133", }; - /* Language ar: Arabic */ - private static final String[] LANGUAGE_ar = { + /* Locale ar: Arabic */ + private static final String[] TEXTS_ar = { /* morekeys_a ~ */ null, null, null, null, null, null, null, null, null, /* ~ single_quotes */ @@ -640,8 +648,8 @@ public final class KeyboardTextsTable { /* morekeys_symbols_percent */ "\\%,\u2030", }; - /* Language az_AZ: Azerbaijani (Azerbaijan) */ - private static final String[] LANGUAGE_az_AZ = { + /* Locale az_AZ: Azerbaijani (Azerbaijan) */ + private static final String[] TEXTS_az_AZ = { // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX /* morekeys_a */ "\u00E2", // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS @@ -688,8 +696,8 @@ public final class KeyboardTextsTable { /* morekeys_g */ "\u011F", }; - /* Language be_BY: Belarusian (Belarus) */ - private static final String[] LANGUAGE_be_BY = { + /* Locale be_BY: Belarusian (Belarus) */ + private static final String[] TEXTS_be_BY = { /* morekeys_a ~ */ null, null, null, null, null, null, /* ~ morekeys_c */ @@ -721,8 +729,8 @@ public final class KeyboardTextsTable { /* morekeys_cyrillic_soft_sign */ "\u044A", }; - /* Language bg: Bulgarian */ - private static final String[] LANGUAGE_bg = { + /* Locale bg: Bulgarian */ + private static final String[] TEXTS_bg = { /* morekeys_a ~ */ null, null, null, null, null, null, /* ~ morekeys_c */ @@ -737,8 +745,8 @@ public final class KeyboardTextsTable { /* keylabel_to_alpha */ "\u0410\u0411\u0412", }; - /* Language ca: Catalan */ - private static final String[] LANGUAGE_ca = { + /* Locale ca: Catalan */ + private static final String[] TEXTS_ca = { // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS @@ -816,8 +824,8 @@ public final class KeyboardTextsTable { /* morekeys_tablet_punctuation */ "!autoColumnOrder!8,\\,,',\u00B7,#,),(,/,;,@,:,-,\",+,\\%,&", }; - /* Language cs: Czech */ - private static final String[] LANGUAGE_cs = { + /* Locale cs: Czech */ + private static final String[] TEXTS_cs = { // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX @@ -894,8 +902,8 @@ public final class KeyboardTextsTable { /* morekeys_r */ "\u0159", }; - /* Language da: Danish */ - private static final String[] LANGUAGE_da = { + /* Locale da: Danish */ + private static final String[] TEXTS_da = { // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE @@ -963,8 +971,8 @@ public final class KeyboardTextsTable { /* morekeys_nordic_row2_11 */ "\u00F6", }; - /* Language de: German */ - private static final String[] LANGUAGE_de = { + /* Locale de: German */ + private static final String[] TEXTS_de = { // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE @@ -1033,8 +1041,8 @@ public final class KeyboardTextsTable { /* morekeys_swiss_row2_11 */ "\u00E0", }; - /* Language el: Greek */ - private static final String[] LANGUAGE_el = { + /* Locale el: Greek */ + private static final String[] TEXTS_el = { /* morekeys_a ~ */ null, null, null, null, null, null, null, null, null, /* ~ single_quotes */ @@ -1045,8 +1053,8 @@ public final class KeyboardTextsTable { /* keylabel_to_alpha */ "\u0391\u0392\u0393", }; - /* Language en: English */ - private static final String[] LANGUAGE_en = { + /* Locale en: English */ + private static final String[] TEXTS_en = { // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX @@ -1094,8 +1102,8 @@ public final class KeyboardTextsTable { /* morekeys_s */ "\u00DF", }; - /* Language eo: Esperanto */ - private static final String[] LANGUAGE_eo = { + /* Locale eo: Esperanto */ + private static final String[] TEXTS_eo = { // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX @@ -1243,8 +1251,8 @@ public final class KeyboardTextsTable { /* keyspec_x */ "\u0109", }; - /* Language es: Spanish */ - private static final String[] LANGUAGE_es = { + /* Locale es: Spanish */ + private static final String[] TEXTS_es = { // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS @@ -1306,8 +1314,8 @@ public final class KeyboardTextsTable { /* morekeys_punctuation */ "!autoColumnOrder!9,\\,,?,!,#,),(,/,;,\u00A1,',@,:,-,\",+,\\%,&,\u00BF", }; - /* Language et_EE: Estonian (Estonia) */ - private static final String[] LANGUAGE_et_EE = { + /* Locale et_EE: Estonian (Estonia) */ + private static final String[] TEXTS_et_EE = { // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE @@ -1409,8 +1417,8 @@ public final class KeyboardTextsTable { /* morekeys_nordic_row2_10 */ "\u00F5", }; - /* Language eu_ES: Basque (Spain) */ - private static final String[] LANGUAGE_eu_ES = { + /* Locale eu_ES: Basque (Spain) */ + private static final String[] TEXTS_eu_ES = { // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS @@ -1463,8 +1471,8 @@ public final class KeyboardTextsTable { /* morekeys_n */ "\u00F1,\u0144", }; - /* Language fa: Persian */ - private static final String[] LANGUAGE_fa = { + /* Locale fa: Persian */ + private static final String[] TEXTS_fa = { /* morekeys_a ~ */ null, null, null, null, null, null, null, null, null, /* ~ single_quotes */ @@ -1601,8 +1609,8 @@ public final class KeyboardTextsTable { /* morekeys_greater_than */ "!fixedColumnOrder!3,!text/keyspec_right_single_angle_quote,!text/keyspec_greater_than_equal,!text/keyspec_greater_than", }; - /* Language fi: Finnish */ - private static final String[] LANGUAGE_fi = { + /* Locale fi: Finnish */ + private static final String[] TEXTS_fi = { // U+00E6: "æ" LATIN SMALL LETTER AE // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE @@ -1651,8 +1659,8 @@ public final class KeyboardTextsTable { /* morekeys_nordic_row2_11 */ "\u00E6", }; - /* Language fr: French */ - private static final String[] LANGUAGE_fr = { + /* Locale fr: French */ + private static final String[] TEXTS_fr = { // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX // U+00E6: "æ" LATIN SMALL LETTER AE @@ -1724,8 +1732,8 @@ public final class KeyboardTextsTable { /* morekeys_swiss_row2_11 */ "\u00E4", }; - /* Language gl_ES: Gallegan (Spain) */ - private static final String[] LANGUAGE_gl_ES = { + /* Locale gl_ES: Gallegan (Spain) */ + private static final String[] TEXTS_gl_ES = { // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS @@ -1778,8 +1786,8 @@ public final class KeyboardTextsTable { /* morekeys_n */ "\u00F1,\u0144", }; - /* Language hi: Hindi */ - private static final String[] LANGUAGE_hi = { + /* Locale hi: Hindi */ + private static final String[] TEXTS_hi = { /* morekeys_a ~ */ null, null, null, null, null, null, null, null, null, /* ~ single_quotes */ @@ -1830,8 +1838,8 @@ public final class KeyboardTextsTable { /* additional_morekeys_symbols_0 */ "0", }; - /* Language hr: Croatian */ - private static final String[] LANGUAGE_hr = { + /* Locale hr: Croatian */ + private static final String[] TEXTS_hr = { /* morekeys_a ~ */ null, null, null, null, null, /* ~ morekeys_i */ @@ -1863,8 +1871,8 @@ public final class KeyboardTextsTable { /* double_angle_quotes */ "!text/double_raqm_laqm", }; - /* Language hu: Hungarian */ - private static final String[] LANGUAGE_hu = { + /* Locale hu: Hungarian */ + private static final String[] TEXTS_hu = { // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX @@ -1917,8 +1925,8 @@ public final class KeyboardTextsTable { /* double_angle_quotes */ "!text/double_raqm_laqm", }; - /* Language hy_AM: Armenian (Armenia) */ - private static final String[] LANGUAGE_hy_AM = { + /* Locale hy_AM: Armenian (Armenia) */ + private static final String[] TEXTS_hy_AM = { /* morekeys_a ~ */ null, null, null, null, null, null, null, null, null, /* ~ single_quotes */ @@ -1970,8 +1978,8 @@ public final class KeyboardTextsTable { /* morekeys_exclamation */ "\u055C,\u00A1", }; - /* Language is: Icelandic */ - private static final String[] LANGUAGE_is = { + /* Locale is: Icelandic */ + private static final String[] TEXTS_is = { // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS // U+00E6: "æ" LATIN SMALL LETTER AE @@ -2027,8 +2035,8 @@ public final class KeyboardTextsTable { /* morekeys_t */ "\u00FE", }; - /* Language it: Italian */ - private static final String[] LANGUAGE_it = { + /* Locale it: Italian */ + private static final String[] TEXTS_it = { // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX @@ -2072,8 +2080,8 @@ public final class KeyboardTextsTable { /* morekeys_i */ "\u00EC,\u00ED,\u00EE,\u00EF,\u012F,\u012B", }; - /* Language iw: Hebrew */ - private static final String[] LANGUAGE_iw = { + /* Locale iw: Hebrew */ + private static final String[] TEXTS_iw = { /* morekeys_a ~ */ null, null, null, null, null, null, /* ~ morekeys_c */ @@ -2130,8 +2138,8 @@ public final class KeyboardTextsTable { /* morekeys_plus */ "\u00B1,\uFB29", }; - /* Language ka_GE: Georgian (Georgia) */ - private static final String[] LANGUAGE_ka_GE = { + /* Locale ka_GE: Georgian (Georgia) */ + private static final String[] TEXTS_ka_GE = { /* morekeys_a ~ */ null, null, null, null, null, null, /* ~ morekeys_c */ @@ -2145,8 +2153,8 @@ public final class KeyboardTextsTable { /* keylabel_to_alpha */ "\u10D0\u10D1\u10D2", }; - /* Language kk: Kazakh */ - private static final String[] LANGUAGE_kk = { + /* Locale kk: Kazakh */ + private static final String[] TEXTS_kk = { /* morekeys_a ~ */ null, null, null, null, null, null, null, null, null, /* ~ single_quotes */ @@ -2202,8 +2210,8 @@ public final class KeyboardTextsTable { /* morekeys_cyrillic_a */ "\u04D9", }; - /* Language km_KH: Khmer (Cambodia) */ - private static final String[] LANGUAGE_km_KH = { + /* Locale km_KH: Khmer (Cambodia) */ + private static final String[] TEXTS_km_KH = { /* morekeys_a ~ */ null, null, null, null, null, null, null, null, null, /* ~ single_quotes */ @@ -2226,8 +2234,8 @@ public final class KeyboardTextsTable { /* morekeys_currency_dollar */ "\u17DB,\u00A2,\u00A3,\u20AC,\u00A5,\u20B1", }; - /* Language ky: Kirghiz */ - private static final String[] LANGUAGE_ky = { + /* Locale ky: Kirghiz */ + private static final String[] TEXTS_ky = { /* morekeys_a ~ */ null, null, null, null, null, null, null, null, null, /* ~ single_quotes */ @@ -2268,8 +2276,8 @@ public final class KeyboardTextsTable { /* morekeys_cyrillic_o */ "\u04E9", }; - /* Language lo_LA: Lao (Laos) */ - private static final String[] LANGUAGE_lo_LA = { + /* Locale lo_LA: Lao (Laos) */ + private static final String[] TEXTS_lo_LA = { /* morekeys_a ~ */ null, null, null, null, null, null, null, null, null, /* ~ single_quotes */ @@ -2285,8 +2293,8 @@ public final class KeyboardTextsTable { /* keyspec_currency */ "\u20AD", }; - /* Language lt: Lithuanian */ - private static final String[] LANGUAGE_lt = { + /* Locale lt: Lithuanian */ + private static final String[] TEXTS_lt = { // U+0105: "ą" LATIN SMALL LETTER A WITH OGONEK // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON @@ -2380,8 +2388,8 @@ public final class KeyboardTextsTable { /* morekeys_k */ "\u0137", }; - /* Language lv: Latvian */ - private static final String[] LANGUAGE_lv = { + /* Locale lv: Latvian */ + private static final String[] TEXTS_lv = { // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE @@ -2474,8 +2482,8 @@ public final class KeyboardTextsTable { /* morekeys_k */ "\u0137", }; - /* Language mk: Macedonian */ - private static final String[] LANGUAGE_mk = { + /* Locale mk: Macedonian */ + private static final String[] TEXTS_mk = { /* morekeys_a ~ */ null, null, null, null, null, null, /* ~ morekeys_c */ @@ -2510,8 +2518,8 @@ public final class KeyboardTextsTable { /* keyspec_south_slavic_row3_8 */ "\u0453", }; - /* Language mn_MN: Mongolian (Mongolia) */ - private static final String[] LANGUAGE_mn_MN = { + /* Locale mn_MN: Mongolian (Mongolia) */ + private static final String[] TEXTS_mn_MN = { /* morekeys_a ~ */ null, null, null, null, null, null, null, null, null, /* ~ single_quotes */ @@ -2527,8 +2535,8 @@ public final class KeyboardTextsTable { /* keyspec_currency */ "\u20AE", }; - /* Language my_MM: Burmese (Myanmar) */ - private static final String[] LANGUAGE_my_MM = { + /* Locale my_MM: Burmese (Myanmar) */ + private static final String[] TEXTS_my_MM = { /* morekeys_a ~ */ null, null, null, null, null, null, null, null, null, /* ~ single_quotes */ @@ -2539,8 +2547,8 @@ public final class KeyboardTextsTable { /* keylabel_to_alpha */ "\u1000\u1001\u1002", }; - /* Language nb: Norwegian Bokmål */ - private static final String[] LANGUAGE_nb = { + /* Locale nb: Norwegian Bokmål */ + private static final String[] TEXTS_nb = { // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE @@ -2593,8 +2601,8 @@ public final class KeyboardTextsTable { /* morekeys_nordic_row2_11 */ "\u00E4", }; - /* Language ne_NP: Nepali (Nepal) */ - private static final String[] LANGUAGE_ne_NP = { + /* Locale ne_NP: Nepali (Nepal) */ + private static final String[] TEXTS_ne_NP = { /* morekeys_a ~ */ null, null, null, null, null, null, null, null, null, /* ~ single_quotes */ @@ -2645,8 +2653,8 @@ public final class KeyboardTextsTable { /* additional_morekeys_symbols_0 */ "0", }; - /* Language nl: Dutch */ - private static final String[] LANGUAGE_nl = { + /* Locale nl: Dutch */ + private static final String[] TEXTS_nl = { // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX @@ -2699,8 +2707,8 @@ public final class KeyboardTextsTable { /* morekeys_y */ "\u0133", }; - /* Language pl: Polish */ - private static final String[] LANGUAGE_pl = { + /* Locale pl: Polish */ + private static final String[] TEXTS_pl = { // U+0105: "ą" LATIN SMALL LETTER A WITH OGONEK // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE @@ -2755,8 +2763,8 @@ public final class KeyboardTextsTable { /* morekeys_l */ "\u0142", }; - /* Language pt: Portuguese */ - private static final String[] LANGUAGE_pt = { + /* Locale pt: Portuguese */ + private static final String[] TEXTS_pt = { // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE @@ -2803,8 +2811,8 @@ public final class KeyboardTextsTable { /* morekeys_c */ "\u00E7,\u010D,\u0107", }; - /* Language rm: Raeto-Romance */ - private static final String[] LANGUAGE_rm = { + /* Locale rm: Raeto-Romance */ + private static final String[] TEXTS_rm = { /* morekeys_a */ null, // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE @@ -2816,8 +2824,8 @@ public final class KeyboardTextsTable { /* morekeys_o */ "\u00F2,\u00F3,\u00F6,\u00F4,\u00F5,\u0153,\u00F8", }; - /* Language ro: Romanian */ - private static final String[] LANGUAGE_ro = { + /* Locale ro: Romanian */ + private static final String[] TEXTS_ro = { // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE // U+0103: "ă" LATIN SMALL LETTER A WITH BREVE @@ -2855,8 +2863,8 @@ public final class KeyboardTextsTable { /* morekeys_t */ "\u021B", }; - /* Language ru: Russian */ - private static final String[] LANGUAGE_ru = { + /* Locale ru: Russian */ + private static final String[] TEXTS_ru = { /* morekeys_a ~ */ null, null, null, null, null, null, /* ~ morekeys_c */ @@ -2888,8 +2896,8 @@ public final class KeyboardTextsTable { /* morekeys_cyrillic_soft_sign */ "\u044A", }; - /* Language sk: Slovak */ - private static final String[] LANGUAGE_sk = { + /* Locale sk: Slovak */ + private static final String[] TEXTS_sk = { // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON @@ -2983,8 +2991,8 @@ public final class KeyboardTextsTable { /* morekeys_k */ "\u0137", }; - /* Language sl: Slovenian */ - private static final String[] LANGUAGE_sl = { + /* Locale sl: Slovenian */ + private static final String[] TEXTS_sl = { /* morekeys_a ~ */ null, null, null, null, null, /* ~ morekeys_i */ @@ -3009,8 +3017,8 @@ public final class KeyboardTextsTable { /* double_angle_quotes */ "!text/double_raqm_laqm", }; - /* Language sr: Serbian */ - private static final String[] LANGUAGE_sr = { + /* Locale sr: Serbian */ + private static final String[] TEXTS_sr = { /* morekeys_a ~ */ null, null, null, null, null, null, /* ~ morekeys_c */ @@ -3069,8 +3077,8 @@ public final class KeyboardTextsTable { /* keyspec_south_slavic_row3_8 */ "\u0452", }; - /* Language sv: Swedish */ - private static final String[] LANGUAGE_sv = { + /* Locale sv: Swedish */ + private static final String[] TEXTS_sv = { // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX @@ -3155,8 +3163,8 @@ public final class KeyboardTextsTable { /* morekeys_nordic_row2_11 */ "\u00E6", }; - /* Language sw: Swahili */ - private static final String[] LANGUAGE_sw = { + /* Locale sw: Swahili */ + private static final String[] TEXTS_sw = { // This is the same as English except morekeys_g. // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE @@ -3209,8 +3217,8 @@ public final class KeyboardTextsTable { /* morekeys_g */ "g\'", }; - /* Language th: Thai */ - private static final String[] LANGUAGE_th = { + /* Locale th: Thai */ + private static final String[] TEXTS_th = { /* morekeys_a ~ */ null, null, null, null, null, null, null, null, null, /* ~ single_quotes */ @@ -3226,8 +3234,8 @@ public final class KeyboardTextsTable { /* keyspec_currency */ "\u0E3F", }; - /* Language tl: Tagalog */ - private static final String[] LANGUAGE_tl = { + /* Locale tl: Tagalog */ + private static final String[] TEXTS_tl = { // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS @@ -3280,8 +3288,8 @@ public final class KeyboardTextsTable { /* morekeys_n */ "\u00F1,\u0144", }; - /* Language tr: Turkish */ - private static final String[] LANGUAGE_tr = { + /* Locale tr: Turkish */ + private static final String[] TEXTS_tr = { // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX /* morekeys_a */ "\u00E2", // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS @@ -3327,8 +3335,8 @@ public final class KeyboardTextsTable { /* morekeys_g */ "\u011F", }; - /* Language uk: Ukrainian */ - private static final String[] LANGUAGE_uk = { + /* Locale uk: Ukrainian */ + private static final String[] TEXTS_uk = { /* morekeys_a ~ */ null, null, null, null, null, null, /* ~ morekeys_c */ @@ -3371,8 +3379,8 @@ public final class KeyboardTextsTable { /* morekeys_cyrillic_ghe */ "\u0491", }; - /* Language vi: Vietnamese */ - private static final String[] LANGUAGE_vi = { + /* Locale vi: Vietnamese */ + private static final String[] TEXTS_vi = { // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE // U+1EA3: "ả" LATIN SMALL LETTER A WITH HOOK ABOVE @@ -3457,8 +3465,8 @@ public final class KeyboardTextsTable { /* keyspec_currency */ "\u20AB", }; - /* Language zu: Zulu */ - private static final String[] LANGUAGE_zu = { + /* Locale zu: Zulu */ + private static final String[] TEXTS_zu = { // This is the same as English // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE @@ -3507,8 +3515,8 @@ public final class KeyboardTextsTable { /* morekeys_s */ "\u00DF", }; - /* Language zz: Alphabet */ - private static final String[] LANGUAGE_zz = { + /* Locale zz: Alphabet */ + private static final String[] TEXTS_zz = { // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX @@ -3646,67 +3654,65 @@ public final class KeyboardTextsTable { /* morekeys_j */ "\u0135", }; - // TODO: Use the language + "_" + region representation for the locale string key. - // Currently we are dropping the region from the key. - private static final Object[] LANGUAGES_AND_TEXTS = { + private static final Object[] LOCALES_AND_TEXTS = { // "locale", TEXT_ARRAY, /* numberOfNonNullText/lengthOf_TEXT_ARRAY localeName */ - "DEFAULT", LANGUAGE_DEFAULT, /* 168/168 default */ - "af", LANGUAGE_af, /* 7/ 12 Afrikaans */ - "ar", LANGUAGE_ar, /* 55/107 Arabic */ - "az", LANGUAGE_az_AZ, /* 8/ 17 Azerbaijani (Azerbaijan) */ - "be", LANGUAGE_be_BY, /* 9/ 32 Belarusian (Belarus) */ - "bg", LANGUAGE_bg, /* 2/ 10 Bulgarian */ - "ca", LANGUAGE_ca, /* 11/120 Catalan */ - "cs", LANGUAGE_cs, /* 17/ 21 Czech */ - "da", LANGUAGE_da, /* 19/ 33 Danish */ - "de", LANGUAGE_de, /* 16/ 91 German */ - "el", LANGUAGE_el, /* 1/ 10 Greek */ - "en", LANGUAGE_en, /* 8/ 11 English */ - "eo", LANGUAGE_eo, /* 26/115 Esperanto */ - "es", LANGUAGE_es, /* 8/ 55 Spanish */ - "et", LANGUAGE_et_EE, /* 22/ 27 Estonian (Estonia) */ - "eu", LANGUAGE_eu_ES, /* 7/ 8 Basque (Spain) */ - "fa", LANGUAGE_fa, /* 58/123 Persian */ - "fi", LANGUAGE_fi, /* 10/ 33 Finnish */ - "fr", LANGUAGE_fr, /* 13/ 91 French */ - "gl", LANGUAGE_gl_ES, /* 7/ 8 Gallegan (Spain) */ - "hi", LANGUAGE_hi, /* 23/ 54 Hindi */ - "hr", LANGUAGE_hr, /* 9/ 19 Croatian */ - "hu", LANGUAGE_hu, /* 9/ 19 Hungarian */ - "hy", LANGUAGE_hy_AM, /* 8/126 Armenian (Armenia) */ - "is", LANGUAGE_is, /* 10/ 15 Icelandic */ - "it", LANGUAGE_it, /* 5/ 5 Italian */ - "iw", LANGUAGE_iw, /* 20/121 Hebrew */ - "ka", LANGUAGE_ka_GE, /* 3/ 10 Georgian (Georgia) */ - "kk", LANGUAGE_kk, /* 15/118 Kazakh */ - "km", LANGUAGE_km_KH, /* 2/119 Khmer (Cambodia) */ - "ky", LANGUAGE_ky, /* 10/ 80 Kirghiz */ - "lo", LANGUAGE_lo_LA, /* 2/ 20 Lao (Laos) */ - "lt", LANGUAGE_lt, /* 18/ 22 Lithuanian */ - "lv", LANGUAGE_lv, /* 18/ 22 Latvian */ - "mk", LANGUAGE_mk, /* 9/ 85 Macedonian */ - "mn", LANGUAGE_mn_MN, /* 2/ 20 Mongolian (Mongolia) */ - "my", LANGUAGE_my_MM, /* 1/ 10 Burmese (Myanmar) */ - "nb", LANGUAGE_nb, /* 11/ 33 Norwegian Bokmål */ - "ne", LANGUAGE_ne_NP, /* 23/ 54 Nepali (Nepal) */ - "nl", LANGUAGE_nl, /* 9/ 12 Dutch */ - "pl", LANGUAGE_pl, /* 10/ 16 Polish */ - "pt", LANGUAGE_pt, /* 6/ 6 Portuguese */ - "rm", LANGUAGE_rm, /* 1/ 2 Raeto-Romance */ - "ro", LANGUAGE_ro, /* 6/ 15 Romanian */ - "ru", LANGUAGE_ru, /* 9/ 32 Russian */ - "sk", LANGUAGE_sk, /* 20/ 22 Slovak */ - "sl", LANGUAGE_sl, /* 8/ 19 Slovenian */ - "sr", LANGUAGE_sr, /* 11/ 85 Serbian */ - "sv", LANGUAGE_sv, /* 21/ 33 Swedish */ - "sw", LANGUAGE_sw, /* 9/ 17 Swahili */ - "th", LANGUAGE_th, /* 2/ 20 Thai */ - "tl", LANGUAGE_tl, /* 7/ 8 Tagalog */ - "tr", LANGUAGE_tr, /* 7/ 17 Turkish */ - "uk", LANGUAGE_uk, /* 11/ 79 Ukrainian */ - "vi", LANGUAGE_vi, /* 8/ 20 Vietnamese */ - "zu", LANGUAGE_zu, /* 8/ 11 Zulu */ - "zz", LANGUAGE_zz, /* 19/109 Alphabet */ + "DEFAULT", TEXTS_DEFAULT, /* 168/168 default */ + "af" , TEXTS_af, /* 7/ 12 Afrikaans */ + "ar" , TEXTS_ar, /* 55/107 Arabic */ + "az_AZ" , TEXTS_az_AZ, /* 8/ 17 Azerbaijani (Azerbaijan) */ + "be_BY" , TEXTS_be_BY, /* 9/ 32 Belarusian (Belarus) */ + "bg" , TEXTS_bg, /* 2/ 10 Bulgarian */ + "ca" , TEXTS_ca, /* 11/120 Catalan */ + "cs" , TEXTS_cs, /* 17/ 21 Czech */ + "da" , TEXTS_da, /* 19/ 33 Danish */ + "de" , TEXTS_de, /* 16/ 91 German */ + "el" , TEXTS_el, /* 1/ 10 Greek */ + "en" , TEXTS_en, /* 8/ 11 English */ + "eo" , TEXTS_eo, /* 26/115 Esperanto */ + "es" , TEXTS_es, /* 8/ 55 Spanish */ + "et_EE" , TEXTS_et_EE, /* 22/ 27 Estonian (Estonia) */ + "eu_ES" , TEXTS_eu_ES, /* 7/ 8 Basque (Spain) */ + "fa" , TEXTS_fa, /* 58/123 Persian */ + "fi" , TEXTS_fi, /* 10/ 33 Finnish */ + "fr" , TEXTS_fr, /* 13/ 91 French */ + "gl_ES" , TEXTS_gl_ES, /* 7/ 8 Gallegan (Spain) */ + "hi" , TEXTS_hi, /* 23/ 54 Hindi */ + "hr" , TEXTS_hr, /* 9/ 19 Croatian */ + "hu" , TEXTS_hu, /* 9/ 19 Hungarian */ + "hy_AM" , TEXTS_hy_AM, /* 8/126 Armenian (Armenia) */ + "is" , TEXTS_is, /* 10/ 15 Icelandic */ + "it" , TEXTS_it, /* 5/ 5 Italian */ + "iw" , TEXTS_iw, /* 20/121 Hebrew */ + "ka_GE" , TEXTS_ka_GE, /* 3/ 10 Georgian (Georgia) */ + "kk" , TEXTS_kk, /* 15/118 Kazakh */ + "km_KH" , TEXTS_km_KH, /* 2/119 Khmer (Cambodia) */ + "ky" , TEXTS_ky, /* 10/ 80 Kirghiz */ + "lo_LA" , TEXTS_lo_LA, /* 2/ 20 Lao (Laos) */ + "lt" , TEXTS_lt, /* 18/ 22 Lithuanian */ + "lv" , TEXTS_lv, /* 18/ 22 Latvian */ + "mk" , TEXTS_mk, /* 9/ 85 Macedonian */ + "mn_MN" , TEXTS_mn_MN, /* 2/ 20 Mongolian (Mongolia) */ + "my_MM" , TEXTS_my_MM, /* 1/ 10 Burmese (Myanmar) */ + "nb" , TEXTS_nb, /* 11/ 33 Norwegian Bokmål */ + "ne_NP" , TEXTS_ne_NP, /* 23/ 54 Nepali (Nepal) */ + "nl" , TEXTS_nl, /* 9/ 12 Dutch */ + "pl" , TEXTS_pl, /* 10/ 16 Polish */ + "pt" , TEXTS_pt, /* 6/ 6 Portuguese */ + "rm" , TEXTS_rm, /* 1/ 2 Raeto-Romance */ + "ro" , TEXTS_ro, /* 6/ 15 Romanian */ + "ru" , TEXTS_ru, /* 9/ 32 Russian */ + "sk" , TEXTS_sk, /* 20/ 22 Slovak */ + "sl" , TEXTS_sl, /* 8/ 19 Slovenian */ + "sr" , TEXTS_sr, /* 11/ 85 Serbian */ + "sv" , TEXTS_sv, /* 21/ 33 Swedish */ + "sw" , TEXTS_sw, /* 9/ 17 Swahili */ + "th" , TEXTS_th, /* 2/ 20 Thai */ + "tl" , TEXTS_tl, /* 7/ 8 Tagalog */ + "tr" , TEXTS_tr, /* 7/ 17 Turkish */ + "uk" , TEXTS_uk, /* 11/ 79 Ukrainian */ + "vi" , TEXTS_vi, /* 8/ 20 Vietnamese */ + "zu" , TEXTS_zu, /* 8/ 11 Zulu */ + "zz" , TEXTS_zz, /* 19/109 Alphabet */ }; static { @@ -3714,11 +3720,11 @@ public final class KeyboardTextsTable { sNameToIndexesMap.put(NAMES[index], index); } - for (int i = 0; i < LANGUAGES_AND_TEXTS.length; i += 2) { - final String language = (String)LANGUAGES_AND_TEXTS[i]; - final String[] textsTable = (String[])LANGUAGES_AND_TEXTS[i + 1]; - sLanguageToTextsTableMap.put(language, textsTable); - sTextsTableToLanguageMap.put(textsTable, language); + for (int i = 0; i < LOCALES_AND_TEXTS.length; i += 2) { + final String locale = (String)LOCALES_AND_TEXTS[i]; + final String[] textsTable = (String[])LOCALES_AND_TEXTS[i + 1]; + sLocaleToTextsTableMap.put(locale, textsTable); + sTextsTableToLocaleMap.put(textsTable, locale); } } } diff --git a/tools/make-keyboard-text/res/src/com/android/inputmethod/keyboard/internal/KeyboardTextsTable.tmpl b/tools/make-keyboard-text/res/src/com/android/inputmethod/keyboard/internal/KeyboardTextsTable.tmpl index b25bfb204..2b5494fa5 100644 --- a/tools/make-keyboard-text/res/src/com/android/inputmethod/keyboard/internal/KeyboardTextsTable.tmpl +++ b/tools/make-keyboard-text/res/src/com/android/inputmethod/keyboard/internal/KeyboardTextsTable.tmpl @@ -19,6 +19,7 @@ package com.android.inputmethod.keyboard.internal; import com.android.inputmethod.latin.utils.CollectionUtils; import java.util.HashMap; +import java.util.Locale; /** * !!!!! DO NOT EDIT THIS FILE !!!!! @@ -44,19 +45,19 @@ import java.util.HashMap; public final class KeyboardTextsTable { // Name to index map. private static final HashMap sNameToIndexesMap = CollectionUtils.newHashMap(); - // Language to texts table map. - private static final HashMap sLanguageToTextsTableMap = + // Locale to texts table map. + private static final HashMap sLocaleToTextsTableMap = CollectionUtils.newHashMap(); // TODO: Remove this variable after debugging. - // Texts table to language maps. - private static final HashMap sTextsTableToLanguageMap = + // Texts table to locale maps. + private static final HashMap sTextsTableToLocaleMap = CollectionUtils.newHashMap(); public static String getText(final String name, final String[] textsTable) { final Integer indexObj = sNameToIndexesMap.get(name); if (indexObj == null) { - throw new RuntimeException("Unknown text name=" + name + " language=" - + sTextsTableToLanguageMap.get(textsTable)); + throw new RuntimeException("Unknown text name=" + name + " locale=" + + sTextsTableToLocaleMap.get(textsTable)); } final int index = indexObj; final String text = (index < textsTable.length) ? textsTable[index] : null; @@ -64,17 +65,24 @@ public final class KeyboardTextsTable { return text; } // Sanity check. - if (index >= 0 && index < LANGUAGE_DEFAULT.length) { - return LANGUAGE_DEFAULT[index]; + if (index >= 0 && index < TEXTS_DEFAULT.length) { + return TEXTS_DEFAULT[index]; } // Throw exception for debugging purpose. throw new RuntimeException("Illegal index=" + index + " for name=" + name - + " language=" + sTextsTableToLanguageMap.get(textsTable)); + + " locale=" + sTextsTableToLocaleMap.get(textsTable)); } - public static String[] getTextsTable(final String language) { - final String[] textsTable = sLanguageToTextsTableMap.get(language); - return textsTable != null ? textsTable : LANGUAGE_DEFAULT; + public static String[] getTextsTable(final Locale locale) { + final String localeKey = locale.toString(); + if (sLocaleToTextsTableMap.containsKey(localeKey)) { + return sLocaleToTextsTableMap.get(localeKey); + } + final String languageKey = locale.getLanguage(); + if (sLocaleToTextsTableMap.containsKey(languageKey)) { + return sLocaleToTextsTableMap.get(languageKey); + } + return TEXTS_DEFAULT; } private static final String[] NAMES = { @@ -85,16 +93,14 @@ public final class KeyboardTextsTable { private static final String EMPTY = ""; /* Default texts */ - private static final String[] LANGUAGE_DEFAULT = { + private static final String[] TEXTS_DEFAULT = { /* @DEFAULT_TEXTS@ */ }; /* @TEXTS@ */ - // TODO: Use the language + "_" + region representation for the locale string key. - // Currently we are dropping the region from the key. - private static final Object[] LANGUAGES_AND_TEXTS = { + private static final Object[] LOCALES_AND_TEXTS = { // "locale", TEXT_ARRAY, /* numberOfNonNullText/lengthOf_TEXT_ARRAY localeName */ - /* @LANGUAGES_AND_TEXTS@ */ + /* @LOCALES_AND_TEXTS@ */ }; static { @@ -102,11 +108,11 @@ public final class KeyboardTextsTable { sNameToIndexesMap.put(NAMES[index], index); } - for (int i = 0; i < LANGUAGES_AND_TEXTS.length; i += 2) { - final String language = (String)LANGUAGES_AND_TEXTS[i]; - final String[] textsTable = (String[])LANGUAGES_AND_TEXTS[i + 1]; - sLanguageToTextsTableMap.put(language, textsTable); - sTextsTableToLanguageMap.put(textsTable, language); + for (int i = 0; i < LOCALES_AND_TEXTS.length; i += 2) { + final String locale = (String)LOCALES_AND_TEXTS[i]; + final String[] textsTable = (String[])LOCALES_AND_TEXTS[i + 1]; + sLocaleToTextsTableMap.put(locale, textsTable); + sTextsTableToLocaleMap.put(textsTable, locale); } } } diff --git a/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/JarUtils.java b/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/JarUtils.java index 8e0f213f4..b892df236 100644 --- a/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/JarUtils.java +++ b/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/JarUtils.java @@ -85,24 +85,24 @@ public final class JarUtils { }); } - // The language is taken from string resource jar entry name (values-/) - // or {@link LocaleUtils#DEFAULT_LANGUAGE_NAME} for the default string resource + // The locale is taken from string resource jar entry name (values-/) + // or {@link LocaleUtils#DEFAULT_LOCALE_KEY} for the default string resource // directory (values/). - public static String getLanguageFromEntryName(final String jarEntryName) { + public static String getLocaleFromEntryName(final String jarEntryName) { final String dirName = jarEntryName.substring(0, jarEntryName.lastIndexOf('/')); final int pos = dirName.lastIndexOf('/'); final String parentName = (pos >= 0) ? dirName.substring(pos + 1) : dirName; - final int languagePos = parentName.indexOf('-'); - if (languagePos < 0) { + final int localePos = parentName.indexOf('-'); + if (localePos < 0) { // Default resource name. - return LocaleUtils.DEFAULT_LANGUAGE_NAME; + return LocaleUtils.DEFAULT_LOCALE_KEY; } - final String language = parentName.substring(languagePos + 1); - final int countryPos = language.indexOf("-r"); - if (countryPos < 0) { - return language; + final String locale = parentName.substring(localePos + 1); + final int regionPos = locale.indexOf("-r"); + if (regionPos < 0) { + return locale; } - return language.replace("-r", "_"); + return locale.replace("-r", "_"); } public static void close(final Closeable stream) { diff --git a/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/LocaleUtils.java b/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/LocaleUtils.java index 3a0ba2bbd..d0f8b4292 100644 --- a/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/LocaleUtils.java +++ b/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/LocaleUtils.java @@ -26,9 +26,9 @@ import java.util.Locale; * for the make-keyboard-text tool. */ public final class LocaleUtils { - public static final String DEFAULT_LANGUAGE_NAME = "DEFAULT"; - public static final String NO_LANGUAGE_CODE = "zz"; - public static final String NO_LANGUAGE_DISPLAY_NAME = "Alphabet"; + public static final String DEFAULT_LOCALE_KEY = "DEFAULT"; + public static final String NO_LANGUAGE_LOCALE_CODE = "zz"; + public static final String NO_LANGUAGE_LOCALE_DISPLAY_NAME = "Alphabet"; private LocaleUtils() { // Intentional empty constructor for utility class. @@ -48,7 +48,8 @@ public final class LocaleUtils { if (retval != null) { return retval; } - String[] localeParams = localeStr.split("_", 3); + final String[] localeParams = localeStr.split("_", 3); + // TODO: Use JDK 7 Locale.Builder to handle a script name. if (localeParams.length == 1) { retval = new Locale(localeParams[0]); } else if (localeParams.length == 2) { @@ -63,11 +64,11 @@ public final class LocaleUtils { } } - public static String getLanguageDisplayName(final String language) { - if (language.equals(NO_LANGUAGE_CODE)) { - return NO_LANGUAGE_DISPLAY_NAME; + public static String getLocaleDisplayName(final String localeString) { + if (localeString.equals(NO_LANGUAGE_LOCALE_CODE)) { + return NO_LANGUAGE_LOCALE_DISPLAY_NAME; } - final Locale locale = constructLocaleFromString(language); + final Locale locale = constructLocaleFromString(localeString); return locale.getDisplayName(Locale.ENGLISH); } } diff --git a/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/MoreKeysResources.java b/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/MoreKeysResources.java index f72fefbf9..c1a9753cc 100644 --- a/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/MoreKeysResources.java +++ b/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/MoreKeysResources.java @@ -25,7 +25,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; -import java.util.Locale; import java.util.TreeMap; import java.util.jar.JarFile; @@ -36,12 +35,13 @@ public class MoreKeysResources { private static final String MARK_NAMES = "@NAMES@"; private static final String MARK_DEFAULT_TEXTS = "@DEFAULT_TEXTS@"; private static final String MARK_TEXTS = "@TEXTS@"; - private static final String MARK_LANGUAGES_AND_TEXTS = "@LANGUAGES_AND_TEXTS@"; + private static final String TEXTS_ARRAY_NAME_PREFIX = "TEXTS_"; + private static final String MARK_LOCALES_AND_TEXTS = "@LOCALES_AND_TEXTS@"; private static final String EMPTY_STRING_VAR = "EMPTY"; private final JarFile mJar; // String resources maps sorted by its language. The language is determined from the jar entry - // name by calling {@link JarUtils#getLanguegFromEntryName(String)}. + // name by calling {@link JarUtils#getLocaleFromEntryName(String)}. private final TreeMap mResourcesMap = new TreeMap(); // Default string resources map. @@ -60,9 +60,9 @@ public class MoreKeysResources { jar, TEXT_RESOURCE_NAME); for (final String entryName : resourceEntryNames) { final StringResourceMap resMap = new StringResourceMap(entryName); - mResourcesMap.put(resMap.mLanguage, resMap); + mResourcesMap.put(resMap.mLocale, resMap); } - mDefaultResourceMap = mResourcesMap.get(LocaleUtils.DEFAULT_LANGUAGE_NAME); + mDefaultResourceMap = mResourcesMap.get(LocaleUtils.DEFAULT_LOCALE_KEY); // Initialize name histogram and names list. final HashMap nameHistogram = mNameHistogram; @@ -72,12 +72,12 @@ public class MoreKeysResources { resourceNamesList.add(res.mName); } // Make name histogram. - for (final String language : mResourcesMap.keySet()) { - final StringResourceMap resMap = mResourcesMap.get(language); + for (final String locale : mResourcesMap.keySet()) { + final StringResourceMap resMap = mResourcesMap.get(locale); if (resMap == mDefaultResourceMap) continue; for (final StringResource res : resMap.getResources()) { if (!mDefaultResourceMap.contains(res.mName)) { - throw new RuntimeException(res.mName + " in " + language + throw new RuntimeException(res.mName + " in " + locale + " doesn't have default resource"); } final int histogramValue = nameHistogram.get(res.mName); @@ -143,8 +143,8 @@ public class MoreKeysResources { dumpDefaultTexts(out); } else if (line.contains(MARK_TEXTS)) { dumpTexts(out); - } else if (line.contains(MARK_LANGUAGES_AND_TEXTS)) { - dumpLanguageMap(out); + } else if (line.contains(MARK_LOCALES_AND_TEXTS)) { + dumpLocalesMap(out); } else { out.println(line); } @@ -165,17 +165,17 @@ public class MoreKeysResources { mDefaultResourceMap.setOutputArraySize(outputArraySize); } - private static String getArrayNameForLanguage(final String language) { - return "LANGUAGE_" + language; + private static String getArrayNameForLocale(final String locale) { + return TEXTS_ARRAY_NAME_PREFIX + locale; } private void dumpTexts(final PrintStream out) { for (final StringResourceMap resMap : mResourcesMap.values()) { - final String language = resMap.mLanguage; + final String locale = resMap.mLocale; if (resMap == mDefaultResourceMap) continue; - out.format(" /* Language %s: %s */\n", - language, LocaleUtils.getLanguageDisplayName(language)); - out.format(" private static final String[] " + getArrayNameForLanguage(language) + out.format(" /* Locale %s: %s */\n", + locale, LocaleUtils.getLocaleDisplayName(locale)); + out.format(" private static final String[] " + getArrayNameForLocale(locale) + " = {\n"); final int outputArraySize = dumpTextsInternal(out, resMap); resMap.setOutputArraySize(outputArraySize); @@ -183,17 +183,16 @@ public class MoreKeysResources { } } - private void dumpLanguageMap(final PrintStream out) { + private void dumpLocalesMap(final PrintStream out) { for (final StringResourceMap resMap : mResourcesMap.values()) { - final String language = resMap.mLanguage; - final Locale locale = LocaleUtils.constructLocaleFromString(language); - final String languageKeyToDump = locale.getCountry().isEmpty() - ? String.format("\"%s\"", language) - : String.format("\"%s\"", locale.getLanguage()); - out.format(" %s, %-15s /* %3d/%3d %s */\n", - languageKeyToDump, getArrayNameForLanguage(language) + ",", + final String locale = resMap.mLocale; + final String localeToDump = locale.equals(LocaleUtils.DEFAULT_LOCALE_KEY) + ? String.format("\"%s\"", locale) + : String.format("\"%s\"%s", locale, " ".substring(locale.length())); + out.format(" %s, %-12s /* %3d/%3d %s */\n", + localeToDump, getArrayNameForLocale(locale) + ",", resMap.getResources().size(), resMap.getOutputArraySize(), - LocaleUtils.getLanguageDisplayName(language)); + LocaleUtils.getLocaleDisplayName(locale)); } } diff --git a/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/StringResourceMap.java b/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/StringResourceMap.java index 8cdc17ded..d7e76ad77 100644 --- a/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/StringResourceMap.java +++ b/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/StringResourceMap.java @@ -34,8 +34,8 @@ import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; public class StringResourceMap { - // Lanugage name. - public final String mLanguage; + // Locale name. + public final String mLocale; // String resource list. private final List mResources; // Name to string resource map. @@ -44,11 +44,11 @@ public class StringResourceMap { // The length of String[] that is created from this {@link StringResourceMap}. The length is // calculated in {@link MoreKeysResources#dumpTexts(OutputStream)} and recorded by // {@link #setOutputArraySize(int)}. The recorded length is used as a part of comment by - // {@link MoreKeysResources#dumpLanguageMap(OutputStream)} via {@link #getOutputArraySize()}. + // {@link MoreKeysResources#dumpLocaleMap(OutputStream)} via {@link #getOutputArraySize()}. private int mOutputArraySize; public StringResourceMap(final String jarEntryName) { - mLanguage = JarUtils.getLanguageFromEntryName(jarEntryName); + mLocale = JarUtils.getLocaleFromEntryName(jarEntryName); final StringResourceHandler handler = new StringResourceHandler(); final SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true);