-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup_translate.py
53 lines (42 loc) · 1.41 KB
/
setup_translate.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
49
50
51
52
53
# -*- coding: utf-8 -*-
# Language extension for distutils Python scripts. Based on this concept:
# http://wiki.maemo.org/Internationalize_a_Python_application
from __future__ import print_function
from distutils import cmd
from distutils.command.build import build as _build
import glob
import os
class build_trans(cmd.Command):
description = 'Compile .po files into .mo files'
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
s = os.path.join('po')
lang_domains = glob.glob(os.path.join(s, '*.pot'))
if len(lang_domains):
for lang in os.listdir(s):
if lang.endswith('.po'):
src = os.path.join(s, lang)
lang = lang[:-3]
destdir = os.path.join('build', 'lib', 'Extensions',
'HistoryZapSelector', 'locale', lang, 'LC_MESSAGES')
if not os.path.exists(destdir):
os.makedirs(destdir)
for lang_domain in lang_domains:
lang_domain = lang_domain.rsplit('/', 1)[1]
dest = os.path.join(destdir, lang_domain[:-3] + 'mo')
print("Language compile %s -> %s" % (src, dest))
if os.system("msgfmt '%s' -o '%s'" % (src, dest)) != 0:
raise Exception("Failed to compile: " + src)
else:
print("we got no domain -> no translation was compiled")
class build(_build):
sub_commands = _build.sub_commands + [('build_trans', None)]
def run(self):
_build.run(self)
cmdclass = {
'build': build,
'build_trans': build_trans,
}