As I'm relatively new to the python ecosystem some things, which may be obvious for many, continue to bother me a bit. The last problem I encounter, which block me for several days, was the following.
In my spare time, I'm developing carp[1], a python3 application to help me manage my different encFS containers. As I want to do clean stuff and learn good practice, I check my source code with flake8. And I setup internationalization too.
If I read the python documentation about the gettext module[2], I see that pushing the following lines at the top of my application is sufficient to have gettext working src:official[3]:
import gettext gettext.install("carp", PATH_TO_PO_FILES)
This, is responsible to install the `_' function in the global namespace. Problem is, if I do that, flake8 keeps complaining that `_' is undeclared. Thus, I stupidly redeclare it this way src:alias[4]:
import gettext gettext.install("carp", PATH_TO_PO_FILES) _ = gettext.gettext
This is not working at all. Even if src:official[3] was working as intended, as soon as I redeclare `_' in src:alias[4], it stops working. Thus for now I come back to the explicit declaration src:working[5] and it works as expected:
import gettext gettext.bindtextdomain("carp", PATH_TO_PO_FILES) gettext.textdomain("carp") _ = gettext.gettext
But still, I'm wondering why src:alias[4] does not work. Did I forget something? Surely, I misunderstood something, but I cannot point it out. Comments and explanations if you have some are very welcome.
/(This post will be cross post to stackoverflow, I'll update it with an answer from there if any good one comes.)/
[2] python documentation about the gettext module (HTTPS) [en]
--
📅 jeudi 2 février 2017 à 10:46
📝 Étienne Pflieger with GNU/Emacs 29.4 (Org mode 9.7.11)