Closed nkhine closed 11 years ago
CLDR seems to have all the collations you would ever dream of (https://github.com/papandreou/node-cldr/tree/master/3rdparty/cldr/common/collation) so I suppose it'd be possible to build an Array.prototype.sort
-compatible comparator function for each locale from that.
I never looked into actually doing it because it seemed like String.prototype.localeCompare
would do the trick. Unfortunately that seems to be crippled in node.js: https://groups.google.com/forum/#!topic/nodejs/edVSlqwM3qM
I guess that makes it worth doing, but there's quite a bit of spec to read up on before even understanding the data: http://www.unicode.org/reports/tr35/tr35-collation.html
Patches very welcome :)
thanks for the reply, will look at the links and see if i can do something.
i just tested the String.prototype.localeCompare
and this has been fixed
☺ locale | grep LC_COLLATE
LC_COLLATE="en_GB.UTF-8"
☺ node
> var x='�', y='�'
undefined
> x.localeCompare(y)
0
I am using this library to localize country names to be displayed as an alpha sorted list for the http://www.zmgc.net website - TZM Network tab
If I change the language to Slovakian for example
Čína
is listed at the end of the list.My list comes from https://github.com/TZM/tzm-blade/blob/master/data/chapters.json file and is being sorted by the following code, note i am using https://github.com/bminer/node-blade template engine which is similar to jade, here is a link to the actual file https://github.com/TZM/tzm-blade/blob/master/views/footer.blade:
The countries list comes from https://github.com/TZM/tzm-blade/blob/master/app/config/apps.coffee#L171
Any advise on how to best improve the code to take into account the linguistic sorting use case would be much appreciated.