we use gettext to implement language system on AART
file structure is as follows
locales
|-- tw
| |-- LC_MESSAGES
| |-- base.mo
| |-- base.po
|-- base.pot
- change all the output to the format _("hello world")
- generate base.pot by
pygettext -d base -o locales/base.pot src/main.py src/welcome/welcome.py...
- copy base.pot to LC_MESSAGES
cp locales/base.pot locales/tw/LC_MESSAGES/base.po
- generate base.mo file by
msgfmt -o locales/tw/LC_MESSAGES/base.mo locales/tw/LC_MESSAGES/base.po
tw = gettext.translation(
"base",
localedir="./locales",
languages=["tw"]
)
tw.install()
_ = tw.gettext
- note: same msgid will only effect one of it