Firefox 55 compatibility: fix Services.locale.getAppLocale() calls

This is a backport of 55b2dc39b.
This commit is contained in:
Dan Stillman 2017-08-09 04:29:13 +02:00
parent f5971279ea
commit c06aa9ed52
4 changed files with 31 additions and 54 deletions

View File

@ -249,16 +249,9 @@ function getTooltipText(button) {
let localeService = Components.classes['@mozilla.org/intl/nslocaleservice;1'] let localeService = Components.classes['@mozilla.org/intl/nslocaleservice;1']
.getService(Components.interfaces.nsILocaleService); .getService(Components.interfaces.nsILocaleService);
Components.utils.import("resource://gre/modules/Services.jsm"); Components.utils.import("resource://gre/modules/Services.jsm");
if (Services.locale.getAppLocale) {
var appLocale = Services.locale.getAppLocale();
}
// Fx <=53
else {
var appLocale = Services.locale.getApplicationLocale();
}
let stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"] let stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"]
.getService(Components.interfaces.nsIStringBundleService); .getService(Components.interfaces.nsIStringBundleService);
let stringBundle = stringBundleService.createBundle(src, appLocale); let stringBundle = stringBundleService.createBundle(src);
text = stringBundle.GetStringFromName('startupError'); text = stringBundle.GetStringFromName('startupError');
} }
} }

View File

@ -266,24 +266,10 @@ Components.utils.import("resource://gre/modules/Services.jsm");
this.locale = this.locale + '-' + this.locale.toUpperCase(); this.locale = this.locale + '-' + this.locale.toUpperCase();
} }
// Load in the localization stringbundle for use by getString(name) _localizedStringBundle = Services.strings.createBundle("chrome://zotero/locale/zotero.properties");
var stringBundleService =
Components.classes["@mozilla.org/intl/stringbundle;1"]
.getService(Components.interfaces.nsIStringBundleService);
if (Services.locale.getAppLocale) {
var appLocale = Services.locale.getAppLocale();
}
// Fx <=53
else {
var appLocale = Services.locale.getApplicationLocale();
}
_localizedStringBundle = stringBundleService.createBundle(
"chrome://zotero/locale/zotero.properties", appLocale);
// Also load the brand as appName // Also load the brand as appName
var brandBundle = stringBundleService.createBundle( var brandBundle = Services.strings.createBundle("chrome://branding/locale/brand.properties");
"chrome://branding/locale/brand.properties", appLocale);
this.appName = brandBundle.GetStringFromName("brandShortName"); this.appName = brandBundle.GetStringFromName("brandShortName");
// Set the locale direction to Zotero.dir // Set the locale direction to Zotero.dir
@ -1496,20 +1482,33 @@ Components.utils.import("resource://gre/modules/Services.jsm");
return this.collation; return this.collation;
} }
Components.utils.import("resource://gre/modules/Services.jsm");
if (Services.locale.getAppLocale) {
var locale = Services.locale.getAppLocale();
}
// Fx <=53
else {
var locale = Services.locale.getApplicationLocale();
locale = locale.getCategory('NSILOCALE_COLLATE');
}
try { try {
// Extract a valid language tag // DEBUG: Is this necessary, or will Intl.Collator just default to the same locales we're
locale = locale.match(/^[a-z]{2}(\-[A-Z]{2})?/)[0]; // passing manually?
var collator = new Intl.Collator(locale, {
let locales;
// Fx55+
if (Services.locale.getAppLocalesAsBCP47) {
locales = Services.locale.getAppLocalesAsBCP47();
}
else {
let locale;
// Fx54
if (Services.locale.getAppLocale) {
locale = Services.locale.getAppLocale();
}
// Fx <=53
else {
locale = Services.locale.getApplicationLocale();
locale = locale.getCategory('NSILOCALE_COLLATE');
}
// Extract a valid language tag
locale = locale.match(/^[a-z]{2}(\-[A-Z]{2})?/)[0];
locales = [locale];
}
var collator = new Intl.Collator(locales, {
ignorePunctuation: true, ignorePunctuation: true,
numeric: true, numeric: true,
sensitivity: 'base' sensitivity: 'base'

View File

@ -4076,14 +4076,9 @@ var ZoteroPane = new function()
} }
if (!errMsg) { if (!errMsg) {
// Get the stringbundle manually
var src = 'chrome://zotero/locale/zotero.properties';
var localeService = Components.classes['@mozilla.org/intl/nslocaleservice;1'].
getService(Components.interfaces.nsILocaleService);
var appLocale = localeService.getApplicationLocale();
var stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"] var stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"]
.getService(Components.interfaces.nsIStringBundleService); .getService(Components.interfaces.nsIStringBundleService);
var stringBundle = stringBundleService.createBundle(src, appLocale); var stringBundle = stringBundleService.createBundle(src);
var errMsg = stringBundle.GetStringFromName('startupError'); var errMsg = stringBundle.GetStringFromName('startupError');
} }

View File

@ -7,19 +7,9 @@ var lastJumpToYearValue;
*/ */
function initLocaleBundle() { function initLocaleBundle() {
var src = 'chrome://zotero/locale/timeline.properties'; var src = 'chrome://zotero/locale/timeline.properties';
Components.utils.import("resource://gre/modules/Services.jsm");
if (Services.locale.getAppLocale) {
var appLocale = Services.locale.getAppLocale();
}
// Fx <=53
else {
var appLocale = Services.locale.getApplicationLocale();
}
var stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"] var stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"]
.getService(Components.interfaces.nsIStringBundleService); .getService(Components.interfaces.nsIStringBundleService);
return stringBundleService.createBundle(src, appLocale); return stringBundleService.createBundle(src);
} }
/* /*