Bug 959061 - Have only one "Chinese, Simplified" item in the Character Encoding menu. r=Unfocused.
authorHenri Sivonen <hsivonen@hsivonen.fi>
Thu, 30 Jan 2014 14:39:25 +0200
changeset 181983 0847543adbfdf67a14d07fd047ae99e24f2607c4
parent 181982 044deda0cbcb8eaa86ac97761eb0dd39379d6375
child 181984 87081cb91d9736356948e50f57f8692e2c9174cf
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersUnfocused
bugs959061
milestone29.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 959061 - Have only one "Chinese, Simplified" item in the Character Encoding menu. r=Unfocused.
browser/base/content/browser.js
toolkit/components/viewsource/content/viewSource.js
toolkit/locales/en-US/chrome/global/charsetMenu.properties
toolkit/modules/CharsetMenu.jsm
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -5216,22 +5216,33 @@ function UpdateCurrentCharset(target) {
 
     // Uncheck previous item
     if (gPrevCharset) {
         var pref_item = charsetMenuGetElement(target, "charset." + gPrevCharset);
         if (pref_item)
           pref_item.setAttribute('checked', 'false');
     }
 
-    var menuitem = charsetMenuGetElement(target, "charset." + wnd.document.characterSet);
+    var menuitem = charsetMenuGetElement(target, "charset." + FoldCharset(wnd.document.characterSet));
     if (menuitem) {
         menuitem.setAttribute('checked', 'true');
     }
 }
 
+function FoldCharset(charset) {
+  // For substantially similar encodings, treat two encodings as the same
+  // for the purpose of the check mark.
+  if (charset == "ISO-8859-8-I") {
+    return "windows-1255";
+  } else if (charset == "gb18030") {
+    return "gbk";
+  }
+  return charset;
+}
+
 function UpdateCharsetDetector(target) {
   var prefvalue;
 
   try {
     prefvalue = gPrefService.getComplexValue("intl.charset.detector", Ci.nsIPrefLocalizedString).data;
   }
   catch (ex) {}
 
@@ -5244,17 +5255,17 @@ function UpdateCharsetDetector(target) {
 }
 
 function UpdateMenus(event) {
   UpdateCurrentCharset(event.target);
   UpdateCharsetDetector(event.target);
 }
 
 function charsetLoadListener() {
-  var charset = window.content.document.characterSet;
+  var charset = FoldCharset(window.content.document.characterSet);
 
   if (charset.length > 0 && (charset != gLastBrowserCharset)) {
     gPrevCharset = gLastBrowserCharset;
     gLastBrowserCharset = charset;
   }
 }
 
 var gPageStyleMenu = {
--- a/toolkit/components/viewsource/content/viewSource.js
+++ b/toolkit/components/viewsource/content/viewSource.js
@@ -692,18 +692,29 @@ function SelectDetector(event)
     str.data = prefvalue;
     gPrefService.setComplexValue("intl.charset.detector", Ci.nsISupportsString, str);
   }
   catch (ex) {
     dump("Failed to set the intl.charset.detector preference.\n");
   }
 }
 
+function FoldCharset(charset) {
+  // For substantially similar encodings, treat two encodings as the same
+  // for the purpose of the check mark.
+  if (charset == "ISO-8859-8-I") {
+    return "windows-1255";
+  } else if (charset == "gb18030") {
+    return "gbk";
+  }
+  return charset;
+}
+
 function UpdateCurrentCharset() {
-  var menuitem = document.getElementById("charset." + content.document.characterSet);
+  var menuitem = document.getElementById("charset." + FoldCharset(content.document.characterSet));
   if (menuitem)
     menuitem.setAttribute("checked", "true");
 }
 
 function UpdateCharsetDetector() {
   var prefvalue;
 
   try {
--- a/toolkit/locales/en-US/chrome/global/charsetMenu.properties
+++ b/toolkit/locales/en-US/chrome/global/charsetMenu.properties
@@ -1,16 +1,19 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 # LOCALIZATION NOTE: The property keys ending with ".key" are for access keys.
 # Localizations may add or delete properties where the property key ends with
 # ".key" as appropriate for the localization. The code that uses this data can
 # deal with the absence of an access key for an item.
+#
+# For gbk, gbk.bis and gbk.bis.key are used to trigger string changes in
+# localizations.
 # 
 # Make sure the keys defined here don't collide with
 # charsetMenuAutodet.accesskey in charsetMenu.dtd.
 #
 # In the en-US version of this file, access keys are given to the following:
 # * UTF-8
 # * All encodings that are the fallback encoding for some locale in Firefox
 # * All encodings that are the fallback encoding for some locale in IE
@@ -56,16 +59,22 @@ ISO-8859-4       = Baltic (ISO)
 
 # Central European
 windows-1250.key =         E
 windows-1250     = Central European (Windows)
 ISO-8859-2.key   =       l
 ISO-8859-2       = Central European (ISO)
 
 # Chinese, Simplified
+# LOCALIZATION NOTE (gbk.bis.key):
+# gbk.bis.key never appears together with gbk.key and, hence, can be the same.
+gbk.bis.key      =          S
+gbk.bis          = Chinese, Simplified
+# The strings gbk.key, gbk and gb18030 are no longer used but are retained
+# in order to enable backout after string freeze, just in case.
 gbk.key          =          S
 gbk              = Chinese, Simplified (GBK)
 gb18030          = Chinese, Simplified (GB18030)
 
 # Chinese, Traditional
 Big5.key         =          T
 Big5             = Chinese, Traditional
 
--- a/toolkit/modules/CharsetMenu.jsm
+++ b/toolkit/modules/CharsetMenu.jsm
@@ -39,17 +39,16 @@ const kEncodings = new Set([
   "windows-1257",
   "ISO-8859-4",
   // "ISO-8859-13", // Hidden since not in menu in IE11
   // Central European
   "windows-1250",
   "ISO-8859-2",
   // Chinese, Simplified
   "gbk",
-  "gb18030",
   // Chinese, Traditional
   "Big5",
   // Cyrillic
   "windows-1251",
   "ISO-8859-5",
   "KOI8-R",
   "KOI8-U",
   "IBM866", // Not in menu in Chromium. Maybe drop this?
@@ -212,22 +211,30 @@ let CharsetMenu = {
   _getDetectorAccesskey: function(detector) {
     try {
       return gBundle.GetStringFromName("charsetMenuAutodet." + detector + ".key");
     } catch (ex) {}
     return "";
   },
 
   _getCharsetLabel: function(charset) {
+    if (charset == "gbk") {
+      // Localization key has been revised
+      charset = "gbk.bis";
+    }
     try {
       return gBundle.GetStringFromName(charset);
     } catch (ex) {}
     return charset;
   },
   _getCharsetAccessKey: function(charset) {
+    if (charset == "gbk") {
+      // Localization key has been revised
+      charset = "gbk.bis";
+    }
     try {
       accesskey = gBundle.GetStringFromName(charset + ".key");
     } catch (ex) {}
     return "";
   },
 };
 
 Object.freeze(CharsetMenu);