Bug 1104589 - Improve the mapping of lang tags to langGroup codes. r=smontagu
authorJonathan Kew <jkew@mozilla.com>
Wed, 26 Nov 2014 10:24:16 +0000
changeset 244031 59961a96fcb9abcc77c102b50dd9d665f6fb16a2
parent 244030 1603cf22d4b66bb470e36db81e6133600fbe1368
child 244032 6379adced8398683787f2efad2ba88487546c87a
push id660
push userraliiev@mozilla.com
push dateWed, 18 Feb 2015 20:30:48 +0000
treeherdermozilla-release@49e493494178 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmontagu
bugs1104589
milestone36.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 1104589 - Improve the mapping of lang tags to langGroup codes. r=smontagu
intl/locale/langGroups.properties
intl/locale/nsLanguageAtomService.cpp
--- a/intl/locale/langGroups.properties
+++ b/intl/locale/langGroups.properties
@@ -176,21 +176,25 @@ ve=x-western
 vi=x-western
 vo=x-western
 wa=x-western
 wo=x-western
 xh=x-western
 yi=he
 yo=x-western
 zh-cn=zh-CN
-# XXX : The following two entries are added as a quick fix (bug 251241).
+# XXX : The following five entries are added as a quick fix (bug 251241, bug 1104589).
 # When we have a general solution for ISO 15924 (script codes), the issue has
 # to be revisited.
 zh-hans=zh-CN
 zh-hant=zh-TW
+zh-latn=x-western
+ja-latn=x-western
+ko-latn=x-western
+#
 zh-tw=zh-TW
 zh-hk=zh-HK
 zh=zh-CN
 zh-min-nan=x-western
 zu=x-western
 #
 #==============================
 #
--- a/intl/locale/nsLanguageAtomService.cpp
+++ b/intl/locale/nsLanguageAtomService.cpp
@@ -100,35 +100,31 @@ nsLanguageAtomService::GetLanguageGroup(
       if (NS_FAILED(InitLangGroupTable())) {
         if (aError) {
           *aError = NS_ERROR_FAILURE;
         }
         return nullptr;
       }
     }
 
-    nsString langStr;
+    nsAutoString langStr;
     aLanguage->ToString(langStr);
 
     nsXPIDLString langGroupStr;
     res = mLangGroups->GetStringFromName(langStr.get(),
                                          getter_Copies(langGroupStr));
-    if (NS_FAILED(res)) {
-      int32_t hyphen = langStr.FindChar('-');
-      if (hyphen >= 0) {
-        nsAutoString truncated(langStr);
-        truncated.Truncate(hyphen);
-        res = mLangGroups->GetStringFromName(truncated.get(),
-                                             getter_Copies(langGroupStr));
-        if (NS_FAILED(res)) {
-          langGroupStr.AssignLiteral("x-unicode");
-        }
-      } else {
+    while (NS_FAILED(res)) {
+      int32_t hyphen = langStr.RFindChar('-');
+      if (hyphen <= 0) {
         langGroupStr.AssignLiteral("x-unicode");
+        break;
       }
+      langStr.Truncate(hyphen);
+      res = mLangGroups->GetStringFromName(langStr.get(),
+                                           getter_Copies(langGroupStr));
     }
 
     nsCOMPtr<nsIAtom> langGroup = do_GetAtom(langGroupStr);
 
     // The hashtable will keep an owning reference to the atom
     mLangToGroup.Put(aLanguage, langGroup);
     retVal = langGroup.get();
   }