How can I sort alphabetically in Swedish using the natsort function?

How can I sort alphabetically in Swedish using the natsort function?

ii13i
Visitor
2 0 0

Hi!

 

I am implementing a shop with swedish as the main locale. Now I have learned that the natural sorting in swedish puts Umlauts at the end, after "z".

 

Question: is there a way to use a function like natsort in conjunction with the selected Locale?

Desired result:

 

 

a = [ "o", "ö", "z", "ä", "å", "a", "á", "æ"]

locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8')
> 'de_DE.UTF-8'
natsorted(a, alg=ns.REAL | ns.LOCALE | ns.IGNORECASE)
> ['a', 'á', 'å', 'ä', 'æ', 'o', 'ö', 'z']

locale.setlocale(locale.LC_ALL, 'sv_SE.UTF-8')
> 'sv_SE.UTF-8'
natsorted(a, alg=ns.REAL | ns.LOCALE | ns.IGNORECASE)
> ['a', 'á', 'o', 'z', 'å', 'ä', 'æ', 'ö']

 

 

 

Thanks!

Reply 1 (1)

ii13i
Visitor
2 0 0

Has this been addressed in the meantime? In the meantime the shop owner had renamed the products so that I can not verify my assumption right now. However, in the menu it does say Alfabetiskt, A–Ö -- as I would expect it with locale aware Alphasort applied.

If it has been addressed by now, this post is obsolete obviously