diff --git a/mesonbuild/scripts/gettext.py b/mesonbuild/scripts/gettext.py index d6bd36622..c3298926e 100644 --- a/mesonbuild/scripts/gettext.py +++ b/mesonbuild/scripts/gettext.py @@ -24,6 +24,9 @@ parser.add_argument('--datadirs', default='') parser.add_argument('--langs', default='') parser.add_argument('--localedir', default='') parser.add_argument('--subdir', default='') +parser.add_argument('--xgettext', default='xgettext') +parser.add_argument('--msgmerge', default='msgmerge') +parser.add_argument('--msginit', default='msginit') parser.add_argument('--extra-args', default='') def read_linguas(src_sub: str) -> T.List[str]: @@ -42,7 +45,7 @@ def read_linguas(src_sub: str) -> T.List[str]: print(f'Could not find file LINGUAS in {src_sub}') return [] -def run_potgen(src_sub: str, pkgname: str, datadirs: str, args: T.List[str]) -> int: +def run_potgen(src_sub: str, xgettext: str, pkgname: str, datadirs: str, args: T.List[str]) -> int: listfile = os.path.join(src_sub, 'POTFILES.in') if not os.path.exists(listfile): listfile = os.path.join(src_sub, 'POTFILES') @@ -55,18 +58,18 @@ def run_potgen(src_sub: str, pkgname: str, datadirs: str, args: T.List[str]) -> child_env['GETTEXTDATADIRS'] = datadirs ofile = os.path.join(src_sub, pkgname + '.pot') - return subprocess.call(['xgettext', '--package-name=' + pkgname, '-p', src_sub, '-f', listfile, + return subprocess.call([xgettext, '--package-name=' + pkgname, '-p', src_sub, '-f', listfile, '-D', os.environ['MESON_SOURCE_ROOT'], '-k_', '-o', ofile] + args, env=child_env) -def update_po(src_sub: str, pkgname: str, langs: T.List[str]) -> int: +def update_po(src_sub: str, msgmerge: str, msginit: str, pkgname: str, langs: T.List[str]) -> int: potfile = os.path.join(src_sub, pkgname + '.pot') for l in langs: pofile = os.path.join(src_sub, l + '.po') if os.path.exists(pofile): - subprocess.check_call(['msgmerge', '-q', '-o', pofile, pofile, potfile]) + subprocess.check_call([msgmerge, '-q', '-o', pofile, pofile, potfile]) else: - subprocess.check_call(['msginit', '--input', potfile, '--output-file', pofile, '--locale', l, '--no-translator']) + subprocess.check_call([msginit, '--input', potfile, '--output-file', pofile, '--locale', l, '--no-translator']) return 0 def run(args: T.List[str]) -> int: @@ -83,11 +86,11 @@ def run(args: T.List[str]) -> int: langs = read_linguas(src_sub) if subcmd == 'pot': - return run_potgen(src_sub, options.pkgname, options.datadirs, extra_args) + return run_potgen(src_sub, options.xgettext, options.pkgname, options.datadirs, extra_args) elif subcmd == 'update_po': - if run_potgen(src_sub, options.pkgname, options.datadirs, extra_args) != 0: + if run_potgen(src_sub, options.xgettext, options.pkgname, options.datadirs, extra_args) != 0: return 1 - return update_po(src_sub, options.pkgname, langs) + return update_po(src_sub, options.msgmerge, options.msginit, options.pkgname, langs) else: print('Unknown subcommand.') return 1 diff --git a/mesonbuild/scripts/itstool.py b/mesonbuild/scripts/itstool.py index fa3b0fa19..72ac3e529 100644 --- a/mesonbuild/scripts/itstool.py +++ b/mesonbuild/scripts/itstool.py @@ -24,11 +24,13 @@ parser.add_argument('command') parser.add_argument('--build-dir', default='') parser.add_argument('-i', '--input', default='') parser.add_argument('-o', '--output', default='') +parser.add_argument('--itstool', default='itstool') parser.add_argument('--its', action='append', default=[]) parser.add_argument('mo_files', nargs='+') -def run_join(build_dir: str, its_files: T.List[str], mo_files: T.List[str], in_fname: str, out_fname: str) -> int: +def run_join(build_dir: str, itstool: str, its_files: T.List[str], mo_files: T.List[str], + in_fname: str, out_fname: str) -> int: if not mo_files: print('No mo files specified to use for translation.') return 1 @@ -53,7 +55,7 @@ def run_join(build_dir: str, its_files: T.List[str], mo_files: T.List[str], in_f shutil.copy(mo_file, tmp_mo_fname) locale_mo_files.append(tmp_mo_fname) - cmd = ['itstool'] + cmd = [itstool] if its_files: for fname in its_files: cmd.extend(['-i', fname]) @@ -73,6 +75,7 @@ def run(args: T.List[str]) -> int: if command == 'join': return run_join(build_dir, + options.itstool, options.its, options.mo_files, options.input, diff --git a/mesonbuild/scripts/msgfmthelper.py b/mesonbuild/scripts/msgfmthelper.py index 3ddc9e6a9..b308f5478 100644 --- a/mesonbuild/scripts/msgfmthelper.py +++ b/mesonbuild/scripts/msgfmthelper.py @@ -22,6 +22,7 @@ parser.add_argument('input') parser.add_argument('output') parser.add_argument('type') parser.add_argument('podir') +parser.add_argument('--msgfmt', default='msgfmt') parser.add_argument('--datadirs', default='') parser.add_argument('args', default=[], metavar='extra msgfmt argument', nargs='*') @@ -32,6 +33,6 @@ def run(args: T.List[str]) -> int: if options.datadirs: env = os.environ.copy() env.update({'GETTEXTDATADIRS': options.datadirs}) - return subprocess.call(['msgfmt', '--' + options.type, '-d', options.podir, + return subprocess.call([options.msgfmt, '--' + options.type, '-d', options.podir, '--template', options.input, '-o', options.output] + options.args, env=env)