Skip to content

Commit

Permalink
Add a way to override the display names for locales in the locale pic…
Browse files Browse the repository at this point in the history
…ker.

In particular, show (the Chinese for) "Chinese (Simplified)" and "Chinese
(Traditional)" instead of "Chinese (China)" and "Chinese (Taiwan)".
  • Loading branch information
Eric Fischer committed Jul 21, 2009
1 parent ba127f5 commit 7ca226b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
13 changes: 13 additions & 0 deletions res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,17 @@
<item>2</item>
</string-array>

<!-- Locales in this list are displayed with the corresponding
name from special_locale_names instead of using the name
from Locale.getDisplayName(). -->
<string-array translatable="false" name="special_locale_codes">
<item>zh_CN</item>
<item>zh_TW</item>
</string-array>

<string-array translatable="false" name="special_locale_names">
<item>中文(简体)</item>
<item>中文 (繁體)</item>
</string-array>

</resources>
27 changes: 21 additions & 6 deletions src/com/android/settings/LocalePicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -70,6 +72,9 @@ public void onCreate(Bundle icicle) {
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);

Expand Down Expand Up @@ -98,15 +103,13 @@ public void onCreate(Bundle icicle) {
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")) {
Expand Down Expand Up @@ -140,6 +143,18 @@ private static String toTitleCase(String s) {
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();
Expand Down

0 comments on commit 7ca226b

Please sign in to comment.