1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is the Firefox Preferences System.
16 * The Initial Developer of the Original Code is
18 * Portions created by the Initial Developer are Copyright (C) 2005
19 * the Initial Developer. All Rights Reserved.
22 * Ben Goodger <ben@mozilla.org>
23 * Adrian Havill <havill@redhat.com>
24 * Steffen Wilberg <steffen.wilberg@web.de>
25 * Daniel Glazman <daniel.glazman@disruptive-innovations.com>
27 * Alternatively, the contents of this file may be used under the terms of
28 * either the GNU General Public License Version 2 or later (the "GPL"), or
29 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
41 /* code chunk needed in dialog or window is
42 <stringbundleset id="languageSet">
43 <stringbundle id="bundleRegions" src="chrome://global/locale/regionNames.properties"/>
44 <stringbundle id="bundleLanguages" src="chrome://global/locale/languageNames.properties"/>
45 <stringbundle id="bundlePreferences" src="chrome://bluegriffon/locale/language.properties"/>
46 <stringbundle id="bundleAccepted" src="resource://gre/res/language.properties"/>
51 var BGLanguagesHelper = {
53 _availableLanguagesList : [],
54 _acceptLanguages : { },
56 _selectedItemID : null,
60 var languageListBox = document.getElementById("languageListBox");
63 this._loadAvailableLanguages();
67 get _activeLanguages()
69 return document.getElementById("activeLanguages");
72 get _availableLanguages()
74 return document.getElementById("availableLanguages");
77 _loadAvailableLanguages: function ()
79 // This is a parser for: resource://gre/res/language.properties
80 // The file is formatted like so:
81 // ab[-cd].accept=true|false
84 var bundleAccepted = document.getElementById("bundleAccepted");
85 var bundleRegions = document.getElementById("bundleRegions");
86 var bundleLanguages = document.getElementById("bundleLanguages");
87 var bundlePreferences = document.getElementById("bundlePreferences");
89 function LanguageInfo(aName, aABCD, aIsVisible)
93 this.isVisible = aIsVisible;
96 // 1) Read the available languages out of language.properties
97 var strings = bundleAccepted.strings;
98 while (strings.hasMoreElements()) {
99 var currString = strings.getNext();
100 if (!(currString instanceof Components.interfaces.nsIPropertyElement))
103 var property = currString.key.split("."); // ab[-cd].accept
104 if (property[1] == "accept") {
105 var abCD = property[0];
106 var abCDPairs = abCD.split("-"); // ab[-cd]
107 var useABCDFormat = abCDPairs.length > 1;
108 var ab = useABCDFormat ? abCDPairs[0] : abCD;
109 var cd = useABCDFormat ? abCDPairs[1] : "";
113 language = bundleLanguages.getString(ab);
115 catch (e) { continue; };
120 region = bundleRegions.getString(cd);
122 catch (e) { continue; }
127 name = bundlePreferences.getFormattedString("languageRegionCodeFormat",
128 [language, region, abCD]);
130 name = bundlePreferences.getFormattedString("languageCodeFormat",
134 var isVisible = currString.value == "true" &&
135 (!(abCD in this._acceptLanguages) || !this._acceptLanguages[abCD]);
136 var li = new LanguageInfo(name, abCD, isVisible);
137 this._availableLanguagesList.push(li);
142 this._buildAvailableLanguageList();
145 _buildAvailableLanguageList: function ()
147 var languageListBox = document.getElementById("languageListBox");
148 if (!languageListBox)
150 while (languageListBox.hasChildNodes())
151 languageListBox.removeChild(languageListBox.firstChild);
153 // Sort the list of languages by name
154 this._availableLanguagesList.sort(function (a, b) {
155 return a.name.localeCompare(b.name);
158 // Load the UI with the data
159 for (var i = 0; i < this._availableLanguagesList.length; ++i) {
160 var abCD = this._availableLanguagesList[i].abcd;
161 if (this._availableLanguagesList[i].isVisible &&
162 (!(abCD in this._acceptLanguages) || !this._acceptLanguages[abCD])) {
163 var menuitem = document.createElement("listitem");
164 menuitem.id = this._availableLanguagesList[i].abcd;
165 languageListBox.appendChild(menuitem);
166 menuitem.setAttribute("label", this._availableLanguagesList[i].name);
167 menuitem.setAttribute("value", this._availableLanguagesList[i].abcd);
172 showChoice: function(aElt)