From 7ca226b15b674613993a6d8d6daf1a679be2a0df Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Mon, 20 Jul 2009 18:16:26 -0700 Subject: [PATCH] Add a way to override the display names for locales in the locale picker. In particular, show (the Chinese for) "Chinese (Simplified)" and "Chinese (Traditional)" instead of "Chinese (China)" and "Chinese (Taiwan)". --- res/values/arrays.xml | 13 +++++++++++ src/com/android/settings/LocalePicker.java | 27 +++++++++++++++++----- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/res/values/arrays.xml b/res/values/arrays.xml index a470acc4f3a..6ec90ca5f56 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -255,4 +255,17 @@ 2 + + + zh_CN + zh_TW + + + + 中文(简体) + 中文 (繁體) + + diff --git a/src/com/android/settings/LocalePicker.java b/src/com/android/settings/LocalePicker.java index 39fb6fabae0..d31e82ca71d 100644 --- a/src/com/android/settings/LocalePicker.java +++ b/src/com/android/settings/LocalePicker.java @@ -39,6 +39,8 @@ public class LocalePicker extends ListActivity { private static final String TAG = "LocalePicker"; Loc[] mLocales; + String[] mSpecialLocaleCodes; + String[] mSpecialLocaleNames; private static class Loc implements Comparable { static Collator sCollator = Collator.getInstance(); @@ -70,6 +72,9 @@ public class LocalePicker extends ListActivity { super.onCreate(icicle); setContentView(getContentView()); + mSpecialLocaleCodes = getResources().getStringArray(R.array.special_locale_codes); + mSpecialLocaleNames = getResources().getStringArray(R.array.special_locale_names); + String[] locales = getAssets().getLocales(); Arrays.sort(locales); @@ -98,15 +103,13 @@ public class LocalePicker extends ListActivity { language)) { Log.v(TAG, "backing up and fixing "+ preprocess[finalSize-1].label+" to "+ - preprocess[finalSize-1].locale. - getDisplayName(l)); + getDisplayName(preprocess[finalSize-1].locale)); preprocess[finalSize-1].label = toTitleCase( - preprocess[finalSize-1]. - locale.getDisplayName(l)); + getDisplayName(preprocess[finalSize-1].locale)); Log.v(TAG, " and adding "+ - toTitleCase(l.getDisplayName(l))); + toTitleCase(getDisplayName(l))); preprocess[finalSize++] = - new Loc(toTitleCase(l.getDisplayName(l)), l); + new Loc(toTitleCase(getDisplayName(l)), l); } else { String displayName; if (s.equals("zz_ZZ")) { @@ -140,6 +143,18 @@ public class LocalePicker extends ListActivity { return Character.toUpperCase(s.charAt(0)) + s.substring(1); } + private String getDisplayName(Locale l) { + String code = l.toString(); + + for (int i = 0; i < mSpecialLocaleCodes.length; i++) { + if (mSpecialLocaleCodes[i].equals(code)) { + return mSpecialLocaleNames[i]; + } + } + + return l.getDisplayName(l); + } + @Override public void onResume() { super.onResume();