34 Components.utils.import(
"resource://app/jsmodules/StringUtils.jsm");
40 var menubar_locales_bundle_module = {};
43 menubar_locales_bundle_module.init_once = 0;
44 menubar_locales_bundle_module.deinit_once = 0;
45 menubar_locales_bundle_module.onLoad =
function()
47 if (menubar_locales_bundle_module.init_once++) { dump(
"WARNING: menubar_locales_bundle double init!!\n");
return; }
50 menubar_locales_bundle_module.onUnload =
function()
52 if (menubar_locales_bundle_module.deinit_once++) { dump(
"WARNING: menubar_locales_bundle double deinit!!\n");
return; }
53 window.removeEventListener(
"load", menubar_locales_bundle_module.onLoad,
false);
54 window.removeEventListener(
"unload", menubar_locales_bundle_module.onUnload,
false);
59 window.addEventListener(
"load", menubar_locales_bundle_module.onLoad,
false);
60 window.addEventListener(
"unload", menubar_locales_bundle_module.onUnload,
false);
71 var
sbIBundle =
new Components.Constructor(
"@songbirdnest.com/Songbird/Bundle;1",
"sbIBundle");
72 menubar_locales_bundle =
new sbIBundle();
73 menubar_locales_bundle.bundleId =
"locales";
74 menubar_locales_bundle.bundleURL =
Application.prefs.getValue(
"songbird.url.locales",
"default");
78 SB_LOG(
"initLocalesBundle",
"" + err );
88 menubar_locales_bundle =
null;
98 onDownloadComplete:
function(
bundle) { menubarLocalesBundleDataReady(); },
99 onError:
function(
bundle) { menubarLocalesBundleDataReady(); },
102 if (!aIID.equals(Components.interfaces.sbIBundleDataListener) &&
103 !aIID.equals(Components.interfaces.nsISupports))
105 throw Components.results.NS_ERROR_NO_INTERFACE;
115 function menubarLocalesBundleDataReady() {
116 if (menubar_locales_bundle.bundleExtensionCount > 0) {
125 function menubarLoadBundledLocales(
menu) {
127 if (menubar_locales_bundle && menubar_locales_bundle.bundleExtensionCount > 0) {
131 var separator =
null;
133 var sbs = Components.classes[
"@mozilla.org/intl/stringbundle;1"]
134 .getService(Components.interfaces.nsIStringBundleService);
135 var langNames = sbs.createBundle(
"chrome://global/locale/languageNames.properties");
136 var regNames = sbs.createBundle(
"chrome://global/locale/regionNames.properties");
138 var elements =
Array();
140 for (var
i=0;
i < menubar_locales_bundle.bundleExtensionCount;
i++) {
141 menubar_locales_bundle.setExtensionInstallFlag(
i,
false);
143 var locale = menubar_locales_bundle.getExtensionAttribute(
i,
"languageTag");
146 var localeID = menubar_locales_bundle.getExtensionAttribute(
i,
"id");
147 var localeMatch = /langpack-([^@]+)/(localeID);
149 locale = localeMatch[1];
156 if (menubar_locales_installed.indexOf(locale) != -1) {
160 var displayName = menubar_locales_bundle.getExtensionAttribute(
i,
"name");
162 var parts = locale.split(/-/);
164 if (parts.length > 1) {
166 [
SBString(parts[0], parts[0], langNames),
167 SBString(parts[1].toLowerCase(), parts[1], regNames)]);
170 [
SBString(parts[0], parts[0], langNames)]);
175 separator = document.createElement(
"menuseparator");
176 separator.setAttribute(
"class", className);
177 menu.appendChild(separator);
180 var item = document.createElement(
"menuitem");
181 item.setAttribute(
"label", displayName);
182 item.setAttribute(
"name",
"locale.switch");
183 item.setAttribute(
"type",
"radio");
184 item.setAttribute(
"class", className);
185 item.setAttribute(
"oncommand",
"installLocaleFromBundle(\"" + locale +
"\", " +
i +
")");
190 for (var
i =0;
i<elements.length;
i++)
menu.appendChild(elements[
i]);
201 function switchLocale(locale, wantmessagebox) {
204 var
prefs = Components.classes[
"@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
205 var curLocale =
"en-US";
207 curLocale = prefs.getCharPref(
"general.useragent.locale");
211 if (locale != curLocale) {
212 prefs.setCharPref(
"general.useragent.locale", locale);
213 if (wantmessagebox) {
214 sbRestartBox_strings(
"message.localization",
"message.needrestart",
"Localization",
"This setting will take effect after you restart Songbird");
220 SB_LOG(
"switchLocale - " + err);
224 var _lastmenu =
null;
233 menubar_locales_installed =
Array();
235 var prefs = Components.classes[
"@mozilla.org/preferences-service;1"]
236 .getService(Components.interfaces.nsIPrefBranch);
237 var curLocale =
"en-US";
239 curLocale = prefs.getCharPref(
"general.useragent.locale");
243 var
cr = Components.classes[
"@mozilla.org/chrome/chrome-registry;1"]
244 .getService(Components.interfaces.nsIToolkitChromeRegistry);
246 var sbs = Components.classes[
"@mozilla.org/intl/stringbundle;1"]
247 .getService(Components.interfaces.nsIStringBundleService);
248 var langNames = sbs.createBundle(
"chrome://global/locale/languageNames.properties");
249 var regNames = sbs.createBundle(
"chrome://global/locale/regionNames.properties");
252 var children =
menu.childNodes;
253 for (var
i = children.length;
i > 0; --
i) {
254 menu.removeChild(children[
i - 1]);
257 var locales = cr.getLocalesForPackage(
"songbird");
258 var elements =
Array();
260 while (locales.hasMore()) {
261 var locale = locales.getNext();
262 menubar_locales_installed.push(locale);
264 var parts = locale.split(/-/);
268 displayName = langNames.GetStringFromName(parts[0]);
269 if (parts.length > 1) {
271 displayName +=
" (" + regNames.GetStringFromName(parts[1].toLowerCase()) +
")";
274 displayName +=
" (" + parts[1] +
")";
279 displayName = locale;
282 var item = document.createElement(
"menuitem");
283 var className =
menu.parentNode.getAttribute(
"class");
285 item.setAttribute(
"label", displayName);
286 item.setAttribute(
"name",
"locale.switch");
287 item.setAttribute(
"type",
"radio");
291 if (flag && flag !=
"") {
292 itemclass = itemclass +
" menuitem-iconic";
293 item.setAttribute(
"image", flag);
295 item.setAttribute(
"class", itemclass);
297 if (curLocale == locale) {
298 item.setAttribute(
"checked",
"true");
300 item.setAttribute(
"oncommand",
"switchLocale(\"" + locale +
"\", true)");
306 for (var
i =0;
i<elements.length;
i++)
menu.appendChild(elements[
i]);
307 if (menubar_locales_bundle && menubar_locales_bundle.bundleDataStatus == Components.interfaces.sbIBundle.BUNDLE_DATA_STATUS_SUCCESS) menubarLoadBundledLocales(
menu);
311 SB_LOG(
"fillLocaleList - " + err);
322 for (var
i=0;
i < menubar_locales_bundle.bundleExtensionCount;
i++) {
323 var
name = menubar_locales_bundle.getExtensionAttribute(
i,
"name");
324 name = name.split(
" ")[0];
325 if (name == locale)
return menubar_locales_bundle.getExtensionAttribute(
i,
"flag");
336 var aname = a.getAttribute(
"label");
337 var bname = b.getAttribute(
"label");
338 if (aname == bname)
return 0;
339 if (aname < bname)
return -1;
351 SBString(
"locales.installconfirm.title",
"Language Download" ),
352 SBString(
"locales.installconfirm.msg",
"This language is not installed, would you like to download and install it?" ) ) ) {
353 if (bundleindex != -1 && menubar_locales_bundle && bundleindex < menubar_locales_bundle.bundleExtensionCount) {
354 for (var
i = 0;
i < menubar_locales_bundle.bundleExtensionCount;
i++) {
355 menubar_locales_bundle.setExtensionInstallFlag(
i,
i == bundleindex);
357 var res = menubar_locales_bundle.installFlaggedExtensions(
window);
359 if (res == menubar_locales_bundle.BUNDLE_INSTALL_SUCCESS) {
360 switchLocale(locale,
true);
363 SBString(
"locales.installfailed.title",
"Language Download" ),
364 SBString(
"locales.installfailed.msg",
"Language installation failed, check your network connectivity!" ) );
373 dump(
"switch_locales.js - " + err);
function SBFormattedString(aKey, aParams, aDefault, aStringBundle)
sbOSDControlService prototype className
var menubar_locales_installed
sbOSDControlService prototype QueryInterface
function SB_LOG(scopeStr, msg)
function SBString(aKey, aDefault, aStringBundle)
function installLocaleFromBundle(locale, bundleindex)
Install a Locale from the Locales Bundle.
var menubar_locales_bundle
function initLocalesBundle()
Initialize the Locales Bundle.
function sortLanguages(a, b)
Sort Locale language names.
var menubarLocalesBundleCB
Locales Bundle listener. Handles download completion and errors.
function resetLocalesBundle()
Reset the Locales Bundle to an uninitialized state.
const MENUBAR_LOCALESBUNDLE_TIMEOUT
function fillLocaleList(menu)
Fill the Locales menu with all available Locales.
function sbRestartBox_strings(titlestring, msgstring, defaulttitle, defaultmsg)
Display a restart message box using strings from the songbird.properties locale file.
Songbird Bundle Interface This is the main bundle management interface, used to get the bundle data...
function getFlagFromBundle(locale)
Get the flag icon URL for a Locales from the Locales bundle.
_getSelectedPageStyle s i