zotero/zotero — Issue #65: citeproc-js needs access to collation object
Author: fbennett
Created: 2012-02-26 12:02:47+00:00
State: open

The Firefox localeCompare() method is (still, incorrectly) performing a binary comparison in Firefox 10. Citeproc-js attempts to work around this by calling up a collation object via the Firefox Components interface, but at some point Components became unavailable to the processor. It's falling back to localeCompare(), and as described [http://forums.zotero.org/discussion/22161/chicago-case-sensitive-order-in-bibliography/ in this thread], we get this kind of thing as a result:

* BMZ
* Berger
* Borg

Making all of Components available may be going to far, but it would be great if a collation sort object could be made available in the processor's environment. Here's the code it's attempting to use at present:

```javascript
try {
var Components;
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);
var collation = collationFactory.CreateCollation(localeService.getApplicationLocale());
strcmp = function(a, b) {
return collation.compareString(1, a, b);
};
CSL.debug("Using collation sort");
} catch (e) {
CSL.debug("NOT using collation sort because: "+e);
strcmp = function (a, b) {
return a.localeCompare(b);
};
}
```