Bug 1014602 - Capitalize first letter of entries in locale switching UI. r=mcomella
authorRichard Newman <rnewman@mozilla.com>
Wed, 11 Jun 2014 13:37:28 -0700
changeset 188317 125b6a8c66f22ffb58c7f581409c468b934b578d
parent 188316 254a1f0dc6419c3fd92d26448115ac323417eed5
child 188318 4fe3277c73840a067b63fba3a52b754c80ee8c73
push id26951
push useremorley@mozilla.com
push dateThu, 12 Jun 2014 14:07:43 +0000
treeherdermozilla-central@4f98802de6ce [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcomella
bugs1014602
milestone33.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1014602 - Capitalize first letter of entries in locale switching UI. r=mcomella
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;