Bug 1014602 - Capitalize first letter of entries in locale switching UI. r=mcomella, a=lmandel
authorRichard Newman <rnewman@mozilla.com>
Wed, 11 Jun 2014 13:37:28 -0700
changeset 207100 24943831690ae2d4f9e02010d6231e2b193a2e07
parent 207099 0cd501f8ba518eaf9e5be3af171e215568923abf
child 207101 63a5404ebb74d7b539c9622c46fab09fb740b150
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcomella, lmandel
bugs1014602
milestone32.0a2
Bug 1014602 - Capitalize first letter of entries in locale switching UI. r=mcomella, a=lmandel
mobile/android/base/preferences/LocaleListPreference.java
--- a/mobile/android/base/preferences/LocaleListPreference.java
+++ b/mobile/android/base/preferences/LocaleListPreference.java
@@ -39,18 +39,37 @@ public class LocaleListPreference extend
         public final String tag;
         private final String nativeName;
 
         public LocaleDescriptor(String tag) {
             this(BrowserLocaleManager.parseLocaleCode(tag), tag);
         }
 
         public LocaleDescriptor(Locale locale, String tag) {
-            this.nativeName = locale.getDisplayName(locale);
             this.tag = tag;
+
+            final String displayName = locale.getDisplayName(locale);
+            if (TextUtils.isEmpty(displayName)) {
+                // There's nothing sane we can do.
+                Log.w(LOG_TAG, "Display name is empty. Using " + locale.toString());
+                this.nativeName = locale.toString();
+                return;
+            }
+
+            // For now, uppercase the first character of LTR locale names.
+            // This is pretty much what Android does. This is a reasonable hack
+            // for Bug 1014602, but it won't generalize to all locales.
+            final byte directionality = Character.getDirectionality(displayName.charAt(0));
+            if (directionality == Character.DIRECTIONALITY_LEFT_TO_RIGHT) {
+                this.nativeName = displayName.substring(0, 1).toUpperCase(locale) +
+                                  displayName.substring(1);
+                return;
+            }
+
+            this.nativeName = displayName;
         }
 
         public String getTag() {
             return this.tag;
         }
 
         public String getDisplayName() {
             return this.nativeName;