diff options
author | 2013-12-13 17:09:16 +0900 | |
---|---|---|
committer | 2013-12-13 17:13:32 +0900 | |
commit | 2fa3693c264a4c150ac307d9bb7f6f8f18cc4ffc (patch) | |
tree | 56a5652edf71dd19d04161f72e3e013608cc2a9c /tools/make-keyboard-text/src/com | |
parent | 18d033405c18a8dc28f60ca22d1d0df23a679384 (diff) | |
download | latinime-2fa3693c264a4c150ac307d9bb7f6f8f18cc4ffc.tar.gz latinime-2fa3693c264a4c150ac307d9bb7f6f8f18cc4ffc.tar.xz latinime-2fa3693c264a4c150ac307d9bb7f6f8f18cc4ffc.zip |
Reset to 9bd6dac4708ad94fd0257c53e977df62b152e20c
The bulk merge from -bayo to klp-dev should not have been merged to master.
Change-Id: I527a03a76f5247e4939a672f27c314dc11cbb854
Diffstat (limited to 'tools/make-keyboard-text/src/com')
-rw-r--r-- | tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/LocaleUtils.java | 61 | ||||
-rw-r--r-- | tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/MoreKeysResources.java | 33 |
2 files changed, 81 insertions, 13 deletions
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 new file mode 100644 index 000000000..9fdc1f607 --- /dev/null +++ b/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/LocaleUtils.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.inputmethod.keyboard.tools; + +import java.util.HashMap; +import java.util.Locale; + +/** + * A class to help with handling Locales in string form. + * + * This is a subset of com/android/inputmethod/latin/utils/LocaleUtils.java in order to use + * for the make-keyboard-text tool. + */ +public final class LocaleUtils { + private LocaleUtils() { + // Intentional empty constructor for utility class. + } + + private static final HashMap<String, Locale> sLocaleCache = new HashMap<String, Locale>(); + + /** + * Creates a locale from a string specification. + */ + public static Locale constructLocaleFromString(final String localeStr) { + if (localeStr == null) { + return null; + } + synchronized (sLocaleCache) { + Locale retval = sLocaleCache.get(localeStr); + if (retval != null) { + return retval; + } + String[] localeParams = localeStr.split("_", 3); + if (localeParams.length == 1) { + retval = new Locale(localeParams[0]); + } else if (localeParams.length == 2) { + retval = new Locale(localeParams[0], localeParams[1]); + } else if (localeParams.length == 3) { + retval = new Locale(localeParams[0], localeParams[1], localeParams[2]); + } + if (retval != null) { + sLocaleCache.put(localeStr, retval); + } + return retval; + } + } +} 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 2643e01ec..a88383025 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 @@ -37,7 +37,7 @@ public class MoreKeysResources { 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 DEFAUT_LANGUAGE_NAME = "DEFAULT"; + private static final String DEFAULT_LANGUAGE_NAME = "DEFAULT"; private static final String ARRAY_NAME_FOR_LANGUAGE = "LANGUAGE_%s"; private static final String EMPTY_STRING_VAR = "EMPTY"; @@ -72,7 +72,7 @@ public class MoreKeysResources { final int languagePos = dirName.indexOf('-'); if (languagePos < 0) { // Default resource. - return DEFAUT_LANGUAGE_NAME; + return DEFAULT_LANGUAGE_NAME; } final String language = dirName.substring(languagePos + 1); final int countryPos = language.indexOf("-r"); @@ -84,10 +84,12 @@ public class MoreKeysResources { public void writeToJava(final String outDir) { final ArrayList<String> list = JarUtils.getNameListing(mJar, JAVA_TEMPLATE); - if (list.isEmpty()) + if (list.isEmpty()) { throw new RuntimeException("Can't find java template " + JAVA_TEMPLATE); - if (list.size() > 1) + } + if (list.size() > 1) { throw new RuntimeException("Found multiple java template " + JAVA_TEMPLATE); + } final String template = list.get(0); final String javaPackage = template.substring(0, template.lastIndexOf('/')); PrintStream ps = null; @@ -131,7 +133,7 @@ public class MoreKeysResources { } private void dumpNames(final PrintStream out) { - final StringResourceMap defaultResMap = mResourcesMap.get(DEFAUT_LANGUAGE_NAME); + final StringResourceMap defaultResMap = mResourcesMap.get(DEFAULT_LANGUAGE_NAME); int id = 0; for (final StringResource res : defaultResMap.getResources()) { out.format(" /* %2d */ \"%s\",\n", id, res.mName); @@ -141,17 +143,17 @@ public class MoreKeysResources { } private void dumpDefaultTexts(final PrintStream out) { - final StringResourceMap defaultResMap = mResourcesMap.get(DEFAUT_LANGUAGE_NAME); + final StringResourceMap defaultResMap = mResourcesMap.get(DEFAULT_LANGUAGE_NAME); dumpTextsInternal(out, defaultResMap, defaultResMap); } private void dumpTexts(final PrintStream out) { - final StringResourceMap defaultResMap = mResourcesMap.get(DEFAUT_LANGUAGE_NAME); + final StringResourceMap defaultResMap = mResourcesMap.get(DEFAULT_LANGUAGE_NAME); final ArrayList<String> allLanguages = new ArrayList<String>(); allLanguages.addAll(mResourcesMap.keySet()); Collections.sort(allLanguages); for (final String language : allLanguages) { - if (language.equals(DEFAUT_LANGUAGE_NAME)) { + if (language.equals(DEFAULT_LANGUAGE_NAME)) { continue; } out.format(" /* Language %s: %s */\n", language, getLanguageDisplayName(language)); @@ -174,17 +176,22 @@ public class MoreKeysResources { allLanguages.addAll(mResourcesMap.keySet()); Collections.sort(allLanguages); for (final String language : allLanguages) { - out.format(" \"%s\", " + ARRAY_NAME_FOR_LANGUAGE + ", /* %s */\n", - language, language, getLanguageDisplayName(language)); + final Locale locale = LocaleUtils.constructLocaleFromString(language); + // If we use a different key, dump the original as comment for now. + final String languageKeyToDump = locale.getCountry().isEmpty() + ? String.format("\"%s\"", language) + : String.format("\"%s\" /* \"%s\" */", locale.getLanguage(), language); + out.format(" %s, " + ARRAY_NAME_FOR_LANGUAGE + ", /* %s */\n", + languageKeyToDump, language, getLanguageDisplayName(language)); } } private static String getLanguageDisplayName(final String language) { - if (language.equals(NO_LANGUAGE_CODE)) { + final Locale locale = LocaleUtils.constructLocaleFromString(language); + if (locale.getLanguage().equals(NO_LANGUAGE_CODE)) { return NO_LANGUAGE_DISPLAY_NAME; - } else { - return new Locale(language).getDisplayLanguage(); } + return locale.getDisplayName(Locale.ENGLISH); } private static void dumpTextsInternal(final PrintStream out, final StringResourceMap resMap, |