问题
We're currently writing a web application based on a threaded python web server framework (cherrypy) and would like to simultaneously support users from multiple locales.
The locale module doesn't appear to be thread safe. Are there 3rd party libraries or modules that provide locale parsing and formatting functionality in a thread-safe way?
Suggestions appreciated!
Regards, Malcolm
回答1:
pyIcu has some such functionality (and other great support for i18n/l10n tasks), and I've been using it some of the time, but it's far from a smooth port of locale
-based code -- you'll basically have to rewrite your code for it. Also, it doesn't support environments where you're not allowed to install arbitrary extensions, such as App Engine and some other hosted environments. Unfortunately I don't know of a good alternative without such constraints:-(.
回答2:
Babel is an excellent library for all your thread-safe i18n needs plus a pluggable framework to extract messages from Python sources and web templates.
来源:https://stackoverflow.com/questions/2186327/thread-safe-locale-techniques