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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
#!/usr/bin/env python
# encoding: utf-8
Import('env')
Import('create_uninstall_target')
Import('VERSION_MAJOR')
Import('VERSION_MINOR')
Import('VERSION_PATCH')
import os
import subprocess
if env['HAVE_MSGFMT']:
for src in env.Glob('*.po'):
lang = os.path.basename(src.get_abspath()[:-3])
dest = lang + '.mo'
cmd = env.AlwaysBuild(
env.Command(dest, src, 'msgfmt $SOURCE -o $TARGET')
)
path = '$PREFIX/share/locale/%s/LC_MESSAGES/rmlint.mo' % lang
if 'install' in COMMAND_LINE_TARGETS:
target = env.InstallAs(path, dest)
env.Depends(target, cmd)
env.Alias('install', [target])
if 'uninstall' in COMMAND_LINE_TARGETS:
create_uninstall_target(env, path)
def xgettext():
return subprocess.call(
'xgettext --package-name rmlint -k_ -kN_ ' \
'--package-version {}.{}.{} --default-domain rmlint ' \
'--add-location=file ' \
'--join-existing ' \
'--output po/rmlint.pot ' \
'--from-code UTF-8 ' \
'$(find src lib -iname "*.[ch]") &&' \
'sed -i "s/CHARSET/UTF-8/g" po/rmlint.pot'.format(
VERSION_MAJOR,
VERSION_MINOR,
VERSION_PATCH
),
shell=True
)
def xgettext_action(target=None, source=None, env=None):
status = xgettext()
if status:
print('Error: xgettext failed')
Exit(status)
def msgmerge(target=None, source=None, env=None):
return subprocess.call(
'set -e;' \
'for p in po/*.po; do' \
' msgmerge --update --backup=none "$p" po/rmlint.pot;' \
'done',
shell=True
)
def msgmerge_action(target=None, source=None, env=None):
status = msgmerge()
if status:
print('Error: msgmerge failed')
Exit(status)
def gettext_action(target=None, source=None, env=None):
status = xgettext()
if status:
('Error: gettext failed while running xgettext')
Exit(status)
status = msgmerge()
if status:
print('Error: gettext failed while running msgmerge')
Exit(status)
if 'xgettext' in COMMAND_LINE_TARGETS:
env.Alias(
'xgettext',
env.Command('xgettext', None, Action(xgettext_action, "Running xgettext"))
)
if 'msgmerge' in COMMAND_LINE_TARGETS:
env.Alias(
'msgmerge',
env.Command('msgmerge', None, Action(msgmerge_action, "Running msgmerge"))
)
if 'gettext' in COMMAND_LINE_TARGETS:
env.Alias(
'gettext',
env.Command('gettext', None, Action(gettext_action, "Running gettext"))
)
|