-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.py
executable file
·48 lines (41 loc) · 1.88 KB
/
tasks.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from invoke import task
import fileinput
import sys
import os
import locale
from datetime import datetime
from glob import glob
from stamp.constants import SUPPORTED_LANGUAGES, VERSION
LOCALE_DIR = 'locale'
if not os.path.exists(LOCALE_DIR):
os.makedirs(LOCALE_DIR)
POTFILE = os.path.join(LOCALE_DIR, 'stamp.pot')
USER_LOCALE = locale.getlocale()
POT_CHANGES = [('SOME DESCRIPTIVE TITLE', 'STAMP'),
('YEAR THE PACKAGE\'S COPYRIGHT HOLDER', '{} arivarton'.format(str(datetime.now().year))),
('PACKAGE', 'stamp'),
('PACKAGE VERSION', VERSION),
('CHARSET', 'UTF-8')]
@task
def translate(c):
c.run("find stamp -type f -name '*.py' \
| xargs xgettext --language=python --add-comments --sort-output --default-domain=stamp --from-code=UTF-8 --keyword='_(' --output={}".format(POTFILE))
for line in fileinput.input('{}'.format(POTFILE), inplace=True):
try:
if POT_CHANGES[0][0] in line:
line = line.replace(*POT_CHANGES.pop(0))
except IndexError:
pass
sys.stdout.write(line)
for lang in SUPPORTED_LANGUAGES:
po_file = os.path.join(LOCALE_DIR, lang + '.po')
if not os.path.isfile(po_file):
c.run("msginit --locale={locale} --no-translator --input={input_file} --output={output_file}".format(locale=lang,
input_file=POTFILE,
output_file=po_file))
else:
c.run("msgmerge --update {output_file} {input_file}".format(output_file=po_file,
input_file=POTFILE))
@task
def test(c):
c.run("python tests/test_cli2.py", in_stream=False)