Bug 1095298 - Ignore 'C' locale when initializing nsLocaleService on Android. r=emk, a=lmandel
authorRichard Newman <rnewman@mozilla.com>
Wed, 12 Nov 2014 08:52:19 -0800
changeset 226033 43fd2720be09
parent 226032 f7dd649eb2f6
child 226034 9e57cec588a9
child 226042 14362f396832
push id4117
push userryanvm@gmail.com
push date2014-11-12 20:41 +0000
treeherdermozilla-beta@43fd2720be09 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemk, lmandel
bugs1095298
milestone34.0
Bug 1095298 - Ignore 'C' locale when initializing nsLocaleService on Android. r=emk, a=lmandel On Android Lollipop, our setlocale call returns "C", rather than the null it returns on earlier Android versions. This impacts locale detection, causing devices to always appear to be in en-US. This patch conditionally ignores "C" if MOZ_WIDGET_ANDROID is set.
intl/locale/nsLocaleService.cpp
--- a/intl/locale/nsLocaleService.cpp
+++ b/intl/locale/nsLocaleService.cpp
@@ -135,17 +135,25 @@ nsLocaleService::nsLocaleService(void)
 
     for( i = 0; i < LocaleListLength; i++ ) {
         nsresult result;
         // setlocale( , "") evaluates LC_* and LANG
         char* lc_temp = setlocale(posix_locale_category[i], "");
         CopyASCIItoUTF16(LocaleList[i], category);
         category_platform = category;
         category_platform.AppendLiteral("##PLATFORM");
-        if (lc_temp != nullptr) {
+
+        bool lc_temp_valid = lc_temp != nullptr;
+
+#if defined(MOZ_WIDGET_ANDROID)
+        // Treat the "C" env as nothing useful. See Bug 1095298.
+        lc_temp_valid = lc_temp_valid && strcmp(lc_temp, "C") != 0;
+#endif
+
+        if (lc_temp_valid) {
             result = nsPosixLocale::GetXPLocale(lc_temp, xpLocale);
             CopyASCIItoUTF16(lc_temp, platformLocale);
         } else {
             if ( lang == nullptr ) {
                 platformLocale.AssignLiteral("en_US");
                 result = nsPosixLocale::GetXPLocale("en-US", xpLocale);
             } else {
                 CopyASCIItoUTF16(lang, platformLocale);