Comment 5 for bug 427568

Revision history for this message
Michael Terry (mterry) wrote : Re: Please sort programs in a locale-friendly way

mpt, that's a weak definition of 'alphabetically' for most non-Latin languages. When the package name translation contains non-Latin characters, what's the sorting plan? Even among romance languages, sorting is trickier than just stripping accents. From that Unicode report linked above:

"In French and a few other languages, however, it is the last accent difference that determines the order, as in row 2.
Normal Accent Ordering cote < coté < côte < côté
French Accent Ordering cote < côte < coté < côté"

Admittedly, that specific example is contrived, but you get my drift.

Again, my favored solution is this:
import PyICU, os
locale = os.environ['LANG'] # TODO: need to strip @ and .UTF-8
collator = PyICU.Collator.createInstance(PyICU.Locale(locale))
list.sort(key=lambda x: collator.getCollationKey(x).getByteArray())

python-pyicu is in main, on the CD.