text/gemini
# Python and gettext setup
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]:
```python - Official way of declaration
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]:
```python - Aliasing the `_' function
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:
```python - Only this way is working 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.)/
=> https://projects.depar.is/carp/ [1] carp (HTTPS) [en]
=> https://docs.python.org/3/library/gettext.html [2] python documentation about the gettext module (HTTPS) [en]
=> src:official [3] src:official (SRC)
=> src:alias [4] src:alias (SRC)
=> src:working [5] src:working (SRC)
--
📅 jeudi 2 février 2017 à 10:46
📝 Étienne Pflieger with GNU/Emacs 29.4 (Org mode 9.7.11)
=> gemini://alltext.umaneti.net/gemlog/tags/bidouille.gmi 🏷️ Bidouille
=> gemini://alltext.umaneti.net/gemlog/tags/python.gmi 🏷️ python
=> gemini://alltext.umaneti.net/gemlog 📜 Back to gemlog
=> gemini://alltext.umaneti.net 🏡 Back to home
=> gemini://alltext.umaneti.net/fronde/README.gmi 🚀 Propelled by fronde
This content has been proxied by September (3851b).