Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Python locale or equivalent in web applications?

Python's locale implementation seems to want to either read the locale from system settings or have it be set via a setlocale call. Neither of these work for me since I'd like to use the capabilities in a web application, where the desired locale is the user's locale.

And there are warnings in the locale docs that make the whole thing scary:

On top of that, some implementation are broken in such a way that frequent locale changes may cause core dumps. This makes the locale somewhat painful to use correctly

And

It is generally a bad idea to call setlocale() in some library routine, since as a side effect it affects the entire program

So, is there a reasonable locale alternative for use in web apps? Is Babel it or are there other alternatives? I'm looking for something that will handle currencies as well as dates and numbers.

[Update] To clarify, I'm most interested in date, number, and currency formatting for various locales.

like image 469
Parand Avatar asked Oct 11 '09 19:10

Parand


1 Answers

locale is no good for any app that needs to support several locales -- it's really badly designed for those apps (basically any server-side app, including web apps). Where feasible, PyICU is a vastly superior solution -- top-quality i18n/L10n support, speed, flexibility (downside: while ICU's docs are good, PyICU's, well, not so much;-). Alas, not always are you allowed to deploy your own extensions...:-(.

In particular, I'm still looking for a solid i18n/L10n solution for App Engine apps -- "translation" per se is the least of issues (you can just switch to the right set of templates), the problem is that there are many other L10n aspects (the ones that ICU supports so well, such as collation rules for example, etc, etc). I guess the already-mentioned Babel is the only sensible place to start from.

like image 137
Alex Martelli Avatar answered Oct 09 '22 08:10

Alex Martelli