aboutsummaryrefslogtreecommitdiffstats
path: root/tools/make-keyboard-text/src
diff options
context:
space:
mode:
Diffstat (limited to 'tools/make-keyboard-text/src')
-rw-r--r--tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/LocaleUtils.java61
-rw-r--r--tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/MoreKeysResources.java33
2 files changed, 13 insertions, 81 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
deleted file mode 100644
index 9fdc1f607..000000000
--- a/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/LocaleUtils.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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 a88383025..2643e01ec 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 DEFAULT_LANGUAGE_NAME = "DEFAULT";
+ private static final String DEFAUT_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 DEFAULT_LANGUAGE_NAME;
+ return DEFAUT_LANGUAGE_NAME;
}
final String language = dirName.substring(languagePos + 1);
final int countryPos = language.indexOf("-r");
@@ -84,12 +84,10 @@ 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;
@@ -133,7 +131,7 @@ public class MoreKeysResources {
}
private void dumpNames(final PrintStream out) {
- final StringResourceMap defaultResMap = mResourcesMap.get(DEFAULT_LANGUAGE_NAME);
+ final StringResourceMap defaultResMap = mResourcesMap.get(DEFAUT_LANGUAGE_NAME);
int id = 0;
for (final StringResource res : defaultResMap.getResources()) {
out.format(" /* %2d */ \"%s\",\n", id, res.mName);
@@ -143,17 +141,17 @@ public class MoreKeysResources {
}
private void dumpDefaultTexts(final PrintStream out) {
- final StringResourceMap defaultResMap = mResourcesMap.get(DEFAULT_LANGUAGE_NAME);
+ final StringResourceMap defaultResMap = mResourcesMap.get(DEFAUT_LANGUAGE_NAME);
dumpTextsInternal(out, defaultResMap, defaultResMap);
}
private void dumpTexts(final PrintStream out) {
- final StringResourceMap defaultResMap = mResourcesMap.get(DEFAULT_LANGUAGE_NAME);
+ final StringResourceMap defaultResMap = mResourcesMap.get(DEFAUT_LANGUAGE_NAME);
final ArrayList<String> allLanguages = new ArrayList<String>();
allLanguages.addAll(mResourcesMap.keySet());
Collections.sort(allLanguages);
for (final String language : allLanguages) {
- if (language.equals(DEFAULT_LANGUAGE_NAME)) {
+ if (language.equals(DEFAUT_LANGUAGE_NAME)) {
continue;
}
out.format(" /* Language %s: %s */\n", language, getLanguageDisplayName(language));
@@ -176,22 +174,17 @@ public class MoreKeysResources {
allLanguages.addAll(mResourcesMap.keySet());
Collections.sort(allLanguages);
for (final String language : allLanguages) {
- 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));
+ out.format(" \"%s\", " + ARRAY_NAME_FOR_LANGUAGE + ", /* %s */\n",
+ language, language, getLanguageDisplayName(language));
}
}
private static String getLanguageDisplayName(final String language) {
- final Locale locale = LocaleUtils.constructLocaleFromString(language);
- if (locale.getLanguage().equals(NO_LANGUAGE_CODE)) {
+ if (language.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,