Bug 445438 - Replace <languageDictionary.js> with a |<stringbundle/>|. r=db48x, sr=jag.
authorSerge Gautherie <sgautherie.bz@free.fr>
Sun, 27 Jul 2008 14:14:43 +0200
changeset 29 9708f7dba8d2a325dca45f6fad46f7e5af34fe5c
parent 28 a8b6674189023bf27bc1ed2facdbad7a4d8ff87f
child 30 4f914bfb27dbe25c712b91e83dab1726ed3cf0a5
push id24
push userstefanh@inbox.com
push dateSun, 27 Jul 2008 12:15:01 +0000
treeherdercomm-central@9708f7dba8d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdb48x, jag
bugs445438
Bug 445438 - Replace <languageDictionary.js> with a |<stringbundle/>|. r=db48x, sr=jag.
suite/browser/jar.mn
suite/browser/languageDictionary.js
suite/browser/linkToolbarHandler.js
suite/browser/linkToolbarOverlay.xul
--- a/suite/browser/jar.mn
+++ b/suite/browser/jar.mn
@@ -1,17 +1,16 @@
 comm.jar:
 % content navigator %content/navigator/ xpcnativewrappers=yes
 % content navigator-platform %content/navigator-platform/ platform xpcnativewrappers=yes
 % content navigator-region %content/navigator-region/ xpcnativewrappers=yes
    content/navigator/aboutAbout.html
    content/navigator/browser.js
    content/navigator/fullScreen.js
    content/navigator/hiddenWindow.xul
-   content/navigator/languageDictionary.js
    content/navigator/linkToolbarHandler.js
    content/navigator/linkToolbarItem.js
    content/navigator/linkToolbarOverlay.js
    content/navigator/linkToolbarOverlay.xul
    content/navigator/mailNavigatorOverlay.xul
    content/navigator/metadata.js
    content/navigator/metadata.xul
    content/navigator/navigator.css
deleted file mode 100644
--- a/suite/browser/languageDictionary.js
+++ /dev/null
@@ -1,89 +0,0 @@
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Eric Hodel's <drbrain@segment7.net> code.
- *
- * The Initial Developer of the Original Code is
- * Eric Hodel.
- * Portions created by the Initial Developer are Copyright (C) 2001
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *      Christopher Hoess <choess@force.stwing.upenn.edu>
- *      Tim Taylor <tim@tool-man.org>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/*
- * LanguageDictionary is a Singleton for looking up a language name
- * given its language code.
- */
-function LanguageDictionary() {
-  this.dictionary = null;
-}
-
-LanguageDictionary.prototype = {
-  lookupLanguageName: function(languageCode) 
-  {
-    if (this.getDictionary()[languageCode])
-      return this.getDictionary()[languageCode];
-    else
-      // XXX: handle non-standard language code's per
-      //    hixie's spec (see bug 2800)
-      return "";
-  },
-
-  getDictionary: function() 
-  {
-    if (!this.dictionary)
-      this.dictionary = LanguageDictionary.createDictionary();
-
-    return this.dictionary;
-  }
-
-}
-
-LanguageDictionary.createDictionary = function() 
-{
-  var dictionary = new Array();
-
-  var e = LanguageDictionary.getLanguageNames().getSimpleEnumeration();
-  while (e.hasMoreElements()) {
-    var property = e.getNext();
-    property = property.QueryInterface(
-        Components.interfaces.nsIPropertyElement);
-    dictionary[property.key] = property.value;
-  }
-
-  return dictionary;
-}
-
-LanguageDictionary.getLanguageNames = function() 
-{
-  return srGetStrBundle(
-      "chrome://global/locale/languageNames.properties");
-}
-
-const languageDictionary = new LanguageDictionary();
\ No newline at end of file
--- a/suite/browser/linkToolbarHandler.js
+++ b/suite/browser/linkToolbarHandler.js
@@ -44,16 +44,26 @@
  * on it's REL attribute and the toolbar item's ID attribute.
  * LinkToolbarHandler is also a Factory and will create 
  * LinkToolbarItems as necessary.
  */
 function LinkToolbarHandler()
 {
   this.items = new Array();
   this.hasItems = false;
+
+  document.addEventListener("load", this.init, true);
+}
+
+LinkToolbarHandler.prototype.init =
+function()
+{
+  document.removeEventListener("load", this.init, true);
+
+  gLanguageBundle = document.getElementById("languageBundle");
 }
 
 LinkToolbarHandler.prototype.handle =
 function(element)
 {
   // XXX: if you're going to re-enable handling of anchor elements,
   //    you'll want to change this to AnchorElementDecorator
   var linkElement = new LinkElementDecorator(element);
@@ -176,17 +186,17 @@ function()
   for (var linkType in this.items)
     this.items[linkType].clear();
 
   // Store the fact that the toolbar is empty
   this.hasItems = false;
 }
 
 const linkToolbarHandler = new LinkToolbarHandler();
-
+var gLanguageBundle;
 
 function LinkElementDecorator(element) {
   /*
    * XXX: this is an incomplete decorator, because it doesn't implement
    *      the full Element interface.  If you need to use a method 
    *      or member in the Element interface, just add it here and
    *      have it delegate to this.element
    *
@@ -227,23 +237,23 @@ function(rel, rev)
     return rev;
   else
     return rel;
 }
 
 LinkElementDecorator.prototype.getTooltip =
 function() 
 {
-  return this.getLongTitle() != "" ? this.getLongTitle() : this.href;
+  return this.getLongTitle() || this.href;
 }
 
 LinkElementDecorator.prototype.getLabel =
 function() 
 {
-  return this.getLongTitle() != "" ? this.getLongTitle() : this.rel;
+  return this.getLongTitle() || this.rel;
 }
 
 LinkElementDecorator.prototype.getLongTitle =
 function() 
 {
   if (this.longTitle == null)
     this.longTitle = this.makeLongTitle();
 
@@ -255,19 +265,27 @@ function()
 {
   var prefix = "";
 
   // XXX: lookup more meaningful and localized version of media, 
   //   i.e. media="print" becomes "Printable" or some such
   // XXX: use localized version of ":" separator
   if (this.media && !/\ball\b|\bscreen\b/i.test(this.media))
     prefix += this.media + ": ";
-  if (this.hreflang)
-    prefix += languageDictionary.lookupLanguageName(this.hreflang)
-          + ": ";
+  if (this.hreflang) {
+    try {
+      prefix += gLanguageBundle.getString(this.hreflang);
+    }
+    catch (e) {
+      // XXX: handle non-standard language codes per
+      //      hixie's spec (see bug 2800)
+    }
+
+    prefix += ": ";
+  }
 
   return this.title ? prefix + this.title : prefix;
 }
 
 function AnchorElementDecorator(element) {
   this.constructor(element);
 }
 AnchorElementDecorator.prototype = new LinkElementDecorator;
--- a/suite/browser/linkToolbarOverlay.xul
+++ b/suite/browser/linkToolbarOverlay.xul
@@ -44,27 +44,31 @@
 
 <overlay id="linkToolbarOverlay" 
          xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
          xmlns:rdf="http://www.mozilla.org/rdf">
 
   <!-- classes -->
   <script type="application/x-javascript" src="chrome://navigator/content/linkToolbarHandler.js" />
   <script type="application/x-javascript" src="chrome://navigator/content/linkToolbarItem.js" />
-  <script type="application/x-javascript" src="chrome://navigator/content/languageDictionary.js" />
 
   <!-- functions -->
   <script type="application/x-javascript" src="chrome://navigator/content/linkToolbarOverlay.js" />
 
   <script type="application/x-javascript">
     <![CDATA[
       document.addEventListener("pageshow", linkToolbarUI.initHandlers, true);
     ]]>
   </script>
 
+  <stringbundleset>
+    <stringbundle id="languageBundle"
+                  src="chrome://global/locale/languageNames.properties"/>
+  </stringbundleset>
+
   <menupopup id="view_toolbars_popup">
     <menu label="&linkToolbar.label;" position="3"
           accesskey="&linkToolbar.accesskey;"
           oncommand="linkToolbarUI.toggleLinkToolbar(event.target)"
           onpopupshowing="linkToolbarUI.initLinkbarVisibilityMenu()">
       <menupopup>
         <menuitem label="&linkToolbarAlways.label;"
                   accesskey="&linkToolbarAlways.accesskey;"