forked from tomerfiliba/plumbum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
translations.py
executable file
·36 lines (26 loc) · 1.02 KB
/
translations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python
# If you are on macOS and using brew, you might need the following first:
# export PATH="/usr/local/opt/gettext/bin:$PATH"
from plumbum import local, FG
from plumbum.cmd import xgettext, msgmerge, msgfmt
translation_dir = local.cwd / 'plumbum/cli/i18n'
template = translation_dir / 'messages.pot'
xgettext['--from-code',
'utf-8',
'-L', 'python',
'--keyword=T_',
'--package-name=Plumbum.cli',
'-o', template,
sorted([x - local.cwd for x in local.cwd / 'plumbum/cli' // '*.py']),
] & FG
for translation in translation_dir // '*.po':
lang = translation.stem
new_tfile = translation.with_suffix('.po.new')
# Merge changes to new file
(msgmerge[translation, template] > new_tfile) & FG
new_tfile.move(translation)
# Render new file into runtime output
local_dir = translation_dir / lang / 'LC_MESSAGES'
if not local_dir.exists():
local_dir.mkdir()
msgfmt['-o', local_dir / 'plumbum.cli.mo', translation] & FG