Bug 728775 - Use M-C code to format dictionary names. r=aceman a=jorgk
authorJorg K
Fri, 03 Jun 2016 01:06:27 +0200
changeset 27214 c5eb848ac878e7a7665087bdcb23e722a1386c12
parent 27213 a580b291487a334c4d4047a88bc89b028418c4b8
child 27215 80242da9baf35c56dc97f69c11c0d0bce64f6397
push id1850
push userclokep@gmail.com
push dateWed, 08 Mar 2017 19:29:12 +0000
treeherdercomm-esr52@028df196b2d9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaceman, jorgk
bugs728775
Bug 728775 - Use M-C code to format dictionary names. r=aceman a=jorgk
editor/ui/dialogs/content/EdSpellCheck.js
mail/components/compose/content/MsgComposeCommands.js
mail/components/compose/content/messengercompose.xul
mail/components/preferences/compose.js
mail/components/preferences/compose.xul
--- a/editor/ui/dialogs/content/EdSpellCheck.js
+++ b/editor/ui/dialogs/content/EdSpellCheck.js
@@ -1,13 +1,15 @@
 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 /* 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/. */
 
+Components.utils.import("resource://gre/modules/InlineSpellChecker.jsm");
+
 var gMisspelledWord;
 var gSpellChecker = null;
 var gAllowSelectWord = true;
 var gPreviousReplaceWord = "";
 var gFirstTime = true;
 var gLastSelectedLang = null;
 var gDictCount = 0;
 
@@ -136,83 +138,30 @@ function InitLanguageMenu(aCurLang)
   // If we're not just starting up and dictionary count
   // hasn't changed then no need to update the menu.
   if (gDictCount == count)
     return;
 
   // Store current dictionary count.
   gDictCount = count;
 
-  // Load the string bundles that will help us map
-  // RFC 1766 strings to UI strings.
-
-  // Load the language string bundle.
-  var languageBundle = document.getElementById("languageBundle");
-  var regionBundle = null;
-  // If we have a language string bundle, load the region string bundle.
-  if (languageBundle)
-    regionBundle = document.getElementById("regionBundle");
-  
-  var menuStr2;
-  var isoStrArray;
-  var langId;
-  var langLabel;
-  var i;
-
-  for (i = 0; i < count; i++)
-  {
-    try
-    {
-      langId = dictList[i];
-      isoStrArray = dictList[i].split(/[-_]/);
-
-      if (languageBundle && isoStrArray[0])
-        langLabel = languageBundle.getString(isoStrArray[0].toLowerCase());
-
-      if (regionBundle && langLabel && isoStrArray.length > 1 && isoStrArray[1])
-      {
-        menuStr2 = regionBundle.getString(isoStrArray[1].toLowerCase());
-        if (menuStr2)
-          langLabel += "/" + menuStr2;
-      }
-
-      if (langLabel && isoStrArray.length > 2 && isoStrArray[2])
-        langLabel += " (" + isoStrArray[2] + ")";
-
-      if (!langLabel)
-        langLabel = langId;
-    }
-    catch (ex)
-    {
-      // getString throws an exception when a key is not found in the
-      // bundle. In that case, just use the original dictList string.
-      langLabel = langId;
-    }
-    dictList[i] = [langLabel, langId];
-  }
-  
-  // sort by locale-aware collation
-  dictList.sort(
-    function compareFn(a, b)
-    {
-      return a[0].localeCompare(b[0]);
-    }
-  );
+  var inlineSpellChecker = new InlineSpellChecker();
+  var sortedList = inlineSpellChecker.sortDictionaryList(dictList);
 
   // Remove any languages from the list.
   var languageMenuPopup = gDialog.LanguageMenulist.firstChild;
   while (languageMenuPopup.firstChild.localName != "menuseparator")
     languageMenuPopup.firstChild.remove();
 
   var defaultItem = null;
 
-  for (i = 0; i < count; i++)
+  for (var i = 0; i < count; i++)
   {
-    var item = gDialog.LanguageMenulist.insertItemAt(i, dictList[i][0], dictList[i][1]);
-    if (aCurLang && dictList[i][1] == aCurLang)
+    var item = gDialog.LanguageMenulist.insertItemAt(i, sortedList[i].label, sortedList[i].id);
+    if (aCurLang && sortedList[i].id == aCurLang)
       defaultItem = item;
   }
 
   // Now make sure the correct item in the menu list is selected.
   if (defaultItem)
   {
     gDialog.LanguageMenulist.selectedItem = defaultItem;
     gLastSelectedLang = defaultItem;
--- a/mail/components/compose/content/MsgComposeCommands.js
+++ b/mail/components/compose/content/MsgComposeCommands.js
@@ -3253,73 +3253,27 @@ function InitLanguageMenu()
 
   // If dictionary count hasn't changed then no need to update the menu.
   if (sDictCount == count)
     return;
 
   // Store current dictionary count.
   sDictCount = count;
 
-  // Load the string bundle that will help us map
-  // RFC 1766 strings to UI strings.
-  var languageBundle = document.getElementById("languageBundle");
-  var isoStrArray;
-  var langId;
-  var langLabel;
-
-  for (let i = 0; i < count; i++)
-  {
-    try
-    {
-      langId = dictList[i];
-      isoStrArray = dictList[i].split(/[-_]/);
-
-      if (languageBundle && isoStrArray[0])
-        langLabel = languageBundle.getString(isoStrArray[0].toLowerCase());
-
-      // the user needs to be able to distinguish between the UK English dictionary
-      // and say the United States English Dictionary. If we have a isoStr value then
-      // wrap it in parentheses and append it to the menu item string. i.e.
-      // English (US) and English (UK)
-      if (!langLabel)
-        langLabel = langId;
-      // if we have a language ID like US or UK, append it to the menu item, and any sub-variety
-      else if (isoStrArray.length > 1 && isoStrArray[1]) {
-        langLabel += ' (' + isoStrArray[1];
-        if (isoStrArray.length > 2 && isoStrArray[2])
-          langLabel += '-' + isoStrArray[2];
-        langLabel += ')';
-      }
-    }
-    catch (ex)
-    {
-      // getString throws an exception when a key is not found in the
-      // bundle. In that case, just use the original dictList string.
-      langLabel = langId;
-    }
-    dictList[i] = [langLabel, langId];
-  }
-
-  // sort by locale-aware collation
-  dictList.sort(
-    function compareFn(a, b)
-    {
-      return a[0].localeCompare(b[0]);
-    }
-  );
+  var sortedList = gSpellChecker.sortDictionaryList(dictList);
 
   // Remove any languages from the list.
   while (languageMenuList.hasChildNodes())
     languageMenuList.lastChild.remove();
 
   for (let i = 0; i < count; i++)
   {
     var item = document.createElement("menuitem");
-    item.setAttribute("label", dictList[i][0]);
-    item.setAttribute("value", dictList[i][1]);
+    item.setAttribute("label", sortedList[i].label);
+    item.setAttribute("value", sortedList[i].id);
     item.setAttribute('type', 'radio');
     languageMenuList.appendChild(item);
   }
 }
 
 function OnShowDictionaryMenu(aTarget)
 {
   InitLanguageMenu();
--- a/mail/components/compose/content/messengercompose.xul
+++ b/mail/components/compose/content/messengercompose.xul
@@ -42,17 +42,16 @@
         persist="screenX screenY width height sizemode"
         lightweightthemes="true"
         fullscreenbutton="true"
         lightweightthemesfooter="status-bar">
 
 <stringbundleset id="stringbundleset">
   <stringbundle id="bundle_composeMsgs" src="chrome://messenger/locale/messengercompose/composeMsgs.properties"/>
   <stringbundle id="bundle_messenger"   src="chrome://messenger/locale/messenger.properties"/>
-  <stringbundle id="languageBundle"     src="chrome://global/locale/languageNames.properties"/>
   <stringbundle id="brandBundle"        src="chrome://branding/locale/brand.properties"/>
 </stringbundleset>
 
 <script type="application/javascript" src="chrome://global/content/printUtils.js"/>
 <script type="application/javascript" src="chrome://messenger/content/accountUtils.js"/>
 <script type="application/javascript" src="chrome://messenger/content/mailCore.js"/>
 <script type="application/javascript" src="chrome://communicator/content/contentAreaClick.js"/>
 <script type="application/javascript" src="chrome://editor/content/editor.js"/>
--- a/mail/components/preferences/compose.js
+++ b/mail/components/preferences/compose.js
@@ -1,13 +1,15 @@
 /* -*- Mode: Javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * 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/. */
 
+Components.utils.import("resource://gre/modules/InlineSpellChecker.jsm");
+
 var gComposePane = {
   mInitialized: false,
   mSpellChecker: null,
   mDictCount : 0,
 
   _loadInContent: Services.prefs.getBoolPref("mail.preferences.inContent"),
 
   init: function ()
@@ -134,77 +136,25 @@ var gComposePane = {
 
     // If dictionary count hasn't changed then no need to update the menu.
     if (this.mDictCount == count)
       return;
 
     // Store current dictionary count.
     this.mDictCount = count;
 
-    // Load the string bundles that will help us map
-    // RFC 1766 strings to UI strings.
-
-    // Load the language string bundle.
-    var languageBundle = document.getElementById("languageBundle");
-    var regionBundle = null;
-    // If we have a language string bundle, load the region string bundle.
-    if (languageBundle)
-      regionBundle = document.getElementById("regionBundle");
-
-    var menuStr2;
-    var isoStrArray;
-    var langId;
-    var langLabel;
-    var i;
-
-    for (i = 0; i < count; i++)
-    {
-      try {
-        langId = dictList[i];
-        isoStrArray = dictList[i].split(/[-_]/);
-
-        if (languageBundle && isoStrArray[0])
-          langLabel = languageBundle.getString(isoStrArray[0].toLowerCase());
-
-        if (regionBundle && langLabel && isoStrArray.length > 1 && isoStrArray[1])
-        {
-          menuStr2 = regionBundle.getString(isoStrArray[1].toLowerCase());
-          if (menuStr2)
-            langLabel += "/" + menuStr2;
-        }
-
-        if (langLabel && isoStrArray.length > 2 && isoStrArray[2])
-          langLabel += " (" + isoStrArray[2] + ")";
-
-        if (!langLabel)
-          langLabel = langId;
-      } catch (ex) {
-        // getString throws an exception when a key is not found in the
-        // bundle. In that case, just use the original dictList string.
-        langLabel = langId;
-      }
-      dictList[i] = [langLabel, langId];
-    }
-
-    // sort by locale-aware collation
-    dictList.sort(
-      function compareFn(a, b)
-      {
-        return a[0].localeCompare(b[0]);
-      }
-    );
+    var inlineSpellChecker = new InlineSpellChecker();
+    var sortedList = inlineSpellChecker.sortDictionaryList(dictList);
 
     // Remove any languages from the list.
-    var languageMenuPopup = languageMenuList.firstChild;
-    while (languageMenuPopup.hasChildNodes())
-      languageMenuPopup.lastChild.remove();
+    languageMenuList.removeAllItems();
 
     // append the dictionaries to the menu list...
-    for (i = 0; i < count; i++)
-      languageMenuList.appendItem(dictList[i][0], dictList[i][1]);
+    for (var i = 0; i < count; i++)
+      languageMenuList.appendItem(sortedList[i].label, sortedList[i].id);
 
     languageMenuList.setInitialSelection();
   },
 
   populateFonts: function()
   {
     var fontsList = document.getElementById("FontSelect");
     try
--- a/mail/components/preferences/compose.xul
+++ b/mail/components/preferences/compose.xul
@@ -16,18 +16,16 @@
 <overlay id="ComposePaneOverlay"
          xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
   <prefpane id="paneCompose" onpaneload="gComposePane.init();">
     <script type="application/javascript" src="chrome://messenger/content/preferences/compose.js"/>
     <script type="application/javascript" src="chrome://global/content/contentAreaUtils.js"/>
     <script type="application/javascript" src="chrome://communicator/content/utilityOverlay.js"/>
 
-    <stringbundle id="languageBundle" src="chrome://global/locale/languageNames.properties"/>
-    <stringbundle id="regionBundle" src="chrome://global/locale/regionNames.properties"/>
     <stringbundle id="bundle_addressBook" src="chrome://messenger/locale/addressbook/addressBook.properties"/>
 
     <preferences id="composePreferences">
       <preference id="mail.preferences.compose.selectedTabIndex" name="mail.preferences.compose.selectedTabIndex" type="int"/>
       <preference id="mail.forward_message_mode" name="mail.forward_message_mode" type="int"/>
       <preference id="mail.forward_add_extension" name="mail.forward_add_extension" type="bool"/>
       <preference id="mail.SpellCheckBeforeSend" name="mail.SpellCheckBeforeSend" type="bool"/>
       <preference id="mail.spellcheck.inline" name="mail.spellcheck.inline" type="bool"/>