I want to sort list of strings with respect to user language preference. I have a multilanguage Python webapp and what is the correct way to sort strings such way?
I know I can set up locale, like this:
import locale
locale.setlocale(locale.LC_ALL, '')
But this should be done on application start (and doc says it is not thread-safe!), is it good idea to set it up in every thread according to current user (request) setting?
I would like something like function locale.strcoll(…) with additional parameter – language that is used for sorting.
Another possible solution is to use SQL server that has good locale support (unfortunately, sqlite is not an option). Then I can put all data to temporary memory table and SELECT them with ORDER BY. IMO it should be better solution than trying to distribute locale settings to multiple processes as kaizer.se’s answer recommends.