Hi there tilde.python,
let's see how many of us are reading this group :)
I've been lately searching for documentation, or examples, on adding internationalization (using gnu gettext) support to a python tool.
This, in itself, is not really difficult, you can do it by adding these
lines to any python script:
```
import gettext
[...]
LOCALE_DIR = '/usr/share/locale'
gettext.bindtextdomain('my_app', LOCALE_DIR)
gettext.textdomain('my_app')
_ = gettext.gettext
```
(that last line lets you then surround any "translatable" string with
the _() function, so later those strings can be extracted and added to
a .pot file for the translators to work on)
Anyway, what I have been looking for is a way to deal with this line: LOCALE_DIR = '/usr/share/locale'
in a way that is as 'cross-platform' as possible (not all systems will
have the language messages under that path), and as simple as possible.
The official gettext documentation covers mostly programs that already
use GNU Autoconf ("the maintainer’s view presented here presumes that
the package already has a configure.ac file and uses GNU Autoconf").
Searching on github for "*.py files that contain 'bindtextdomain' " [1]
returns a huge variety of methods to come up with a path to use. And
searching the internet with duckduckgo is proving to be quite useless
and seems to return the same "tutorial" regurgitated via different
"blogs", possibly most of them ai-generated one way or another.
[1]
https://github.com/search?q=path%3A**%2F*py+bindtextdomain&type=code
So I was wondering, tilde python people: has anyone of you dealt with
this situation before? is there a "best practice" hidden somewhere on
the internet? (I'm not really a python expert of any kind, so maybe
there is a python guide out there that I'm just failing to find...)
Thanks in advance for any hint you can give me! and see you around!
--
jmcs <
jmcs@tilde.club>
--- Synchronet 3.20a-Linux NewsLink 1.2