diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index a06a8c9392..71aebaebd8 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -67,7 +67,6 @@ Components.utils.import("resource://gre/modules/Services.jsm"); this.safeDebug = safeDebug; this.getString = getString; this.localeJoin = localeJoin; - this.getLocaleCollation = getLocaleCollation; this.setFontSize = setFontSize; this.flattenArguments = flattenArguments; this.getAncestorByTagName = getAncestorByTagName; @@ -1467,12 +1466,32 @@ Components.utils.import("resource://gre/modules/Services.jsm"); } - function getLocaleCollation() { + this.getLocaleCollation = function () { + if (this.collation) { + return this.collation; + } + var localeService = Components.classes["@mozilla.org/intl/nslocaleservice;1"] - .getService(Components.interfaces.nsILocaleService); - var collationFactory = Components.classes["@mozilla.org/intl/collation-factory;1"] - .getService(Components.interfaces.nsICollationFactory); - return collationFactory.CreateCollation(localeService.getApplicationLocale()); + .getService(Components.interfaces.nsILocaleService); + var appLocale = localeService.getApplicationLocale(); + + // Use nsICollation before Fx29 + if (Zotero.platformMajorVersion < 29) { + var localeService = Components.classes["@mozilla.org/intl/nslocaleservice;1"] + .getService(Components.interfaces.nsILocaleService); + var collationFactory = Components.classes["@mozilla.org/intl/collation-factory;1"] + .getService(Components.interfaces.nsICollationFactory); + return this.collation = collationFactory.CreateCollation(appLocale); + } + + var locale = appLocale.getCategory('NSILOCALE_COLLATE'); + var collator = new Intl.Collator(locale); + // Until old code is updated, pretend we're returning an nsICollation + return this.collation = { + compareString: function (_, a, b) { + return collator.compare(a, b); + } + }; }