On Wed, Oct 21, 2020 at 3:02 AM Serhiy Storchaka <storchaka@gmail.com> wrote:
21.10.20 05:23, Steve Barnes пише:
> Of course there is also the problem of detecting any functions assigned
> to _ or _T that may be called - otherwise there is a risk of breaking
> the typical gettext usage in I18n!

gettext is usually mapped to global _, so it is not affected.

Also, even if eliminate globals, gettext is mapped using
gettext.install() which does not use assignment to _. It does:

        import builtins
        builtins.__dict__['_'] = self.gettext
In a program I work on, I found that this strategy did not work: I (apparently) do need to assign _ locally within each function where needed.  

This program includes, as an option, a custom Python REPL  where _ has its usual meaning, while having the possibility to change language during a session. Attempting to use the standard global gettext _ breaks that.

Furthermore, I want the user to be able to specify either a two letter code (say 'fr') or a four letter code (say fr_CA) such that if the latter were not found, it would look for the corresponding generic two-letter code (fr) before falling back to the default (en) as a last resort.  As far as I know, a straight gettext.install does not allow that.  

I admit that my usage might not be typical.

André Roberge


 
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/73KKPXJXQE3MQYK6RNPFOCO6472YFOEJ/
Code of Conduct: http://python.org/psf/codeofconduct/