From 979e62714cfe1f431f77fec121f7c014916ccbe1 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 25 Jun 2014 12:14:28 -0400 Subject: [PATCH] Fix startup errors in some non-English locales in Fx30 on OS X nsICollation broke for some locales. (Testing requires changing the language setting in Language & Region and then restarting the computer. The change seems to not fully go into effect until then, even though the UI changes.) This is fixed in Nightly, but we can work around it by using the new Intl.Collator. --- chrome/content/zotero/xpcom/zotero.js | 31 +++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) 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); + } + }; }