diff options
author | Patrick Griffis <tingping@tingping.se> | 2016-12-02 23:46:50 -0500 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2016-12-06 20:29:20 +0200 |
commit | 155617e539a9aeccda6bd186398123b9d5521ed4 (patch) | |
tree | c30a482d0498d79b2dc5ba9e7eb5fc8a670ba313 | |
parent | b28da68faf2485fff018fb59bae2030c379f2376 (diff) | |
download | meson-155617e539a9aeccda6bd186398123b9d5521ed4.zip meson-155617e539a9aeccda6bd186398123b9d5521ed4.tar.gz meson-155617e539a9aeccda6bd186398123b9d5521ed4.tar.bz2 |
i18n: Improve language handling
- Fix LINGUAS changes not being picked up
- Fix multiple langs per line in LINGUAS
- Make empty languages acceptable
Fixes #1127
-rw-r--r-- | mesonbuild/modules/i18n.py | 27 | ||||
-rw-r--r-- | mesonbuild/scripts/gettext.py | 21 |
2 files changed, 31 insertions, 17 deletions
diff --git a/mesonbuild/modules/i18n.py b/mesonbuild/modules/i18n.py index 13394c1..29db960 100644 --- a/mesonbuild/modules/i18n.py +++ b/mesonbuild/modules/i18n.py @@ -60,22 +60,11 @@ class I18nModule: '--template', '@INPUT@', '-d', podir, '-o', '@OUTPUT@'] return build.CustomTarget(kwargs['output'] + '_merge', state.subdir, kwargs) - @staticmethod - def _read_linguas(state): - linguas = path.join(state.environment.get_source_dir(), state.subdir, 'LINGUAS') - try: - with open(linguas) as f: - return [line.strip() for line in f if not line.strip().startswith('#')] - except (FileNotFoundError, PermissionError): - return [] - def gettext(self, state, args, kwargs): if len(args) != 1: raise coredata.MesonException('Gettext requires one positional argument (package name).') packagename = args[0] - languages = mesonlib.stringlistify(kwargs.get('languages', self._read_linguas(state))) - if len(languages) == 0: - raise coredata.MesonException('List of languages empty.') + languages = mesonlib.stringlistify(kwargs.get('languages', [])) datadirs = mesonlib.stringlistify(kwargs.get('data_dirs', [])) extra_args = mesonlib.stringlistify(kwargs.get('args', [])) @@ -88,7 +77,7 @@ class I18nModule: extra_args = set(preset_args + extra_args) pkg_arg = '--pkgname=' + packagename - lang_arg = '--langs=' + '@@'.join(languages) + lang_arg = '--langs=' + '@@'.join(languages) if languages else None datadirs = '--datadirs=' + ':'.join(datadirs) if datadirs else None extra_args = '--extra-args=' + '@@'.join(extra_args) if extra_args else None @@ -99,10 +88,14 @@ class I18nModule: potargs.append(extra_args) pottarget = build.RunTarget(packagename + '-pot', sys.executable, potargs, [], state.subdir) - gmoargs = [state.environment.get_build_command(), '--internal', 'gettext', 'gen_gmo', lang_arg] + gmoargs = [state.environment.get_build_command(), '--internal', 'gettext', 'gen_gmo'] + if lang_arg: + gmoargs.append(lang_arg) gmotarget = build.RunTarget(packagename + '-gmo', sys.executable, gmoargs, [], state.subdir) - updatepoargs = [state.environment.get_build_command(), '--internal', 'gettext', 'update_po', pkg_arg, lang_arg] + updatepoargs = [state.environment.get_build_command(), '--internal', 'gettext', 'update_po', pkg_arg] + if lang_arg: + updatepoargs.append(lang_arg) if datadirs: updatepoargs.append(datadirs) if extra_args: @@ -113,7 +106,9 @@ class I18nModule: '--internal', 'gettext', 'install', '--subdir=' + state.subdir, '--localedir=' + state.environment.coredata.get_builtin_option('localedir'), - pkg_arg, lang_arg] + pkg_arg] + if lang_arg: + installcmd.append(lang_arg) iscript = build.InstallScript(installcmd) return [pottarget, gmotarget, iscript, updatepotarget] diff --git a/mesonbuild/scripts/gettext.py b/mesonbuild/scripts/gettext.py index 16096b8..be2f94b 100644 --- a/mesonbuild/scripts/gettext.py +++ b/mesonbuild/scripts/gettext.py @@ -27,6 +27,22 @@ parser.add_argument('--localedir', default='') parser.add_argument('--subdir', default='') parser.add_argument('--extra-args', default='') +def read_linguas(src_sub): + # Syntax of this file is documented here: + # https://www.gnu.org/software/gettext/manual/html_node/po_002fLINGUAS.html + linguas = os.path.join(src_sub, 'LINGUAS') + try: + langs = [] + with open(linguas) as f: + for line in f: + line = line.strip() + if line and not line.startswith('#'): + langs += line.split() + return langs + except (FileNotFoundError, PermissionError): + print('Could not find file LINGUAS in {}'.format(src_sub)) + return [] + def run_potgen(src_sub, pkgname, datadirs, args): listfile = os.path.join(src_sub, 'POTFILES') if not os.path.exists(listfile): @@ -71,12 +87,15 @@ def do_install(src_sub, bld_sub, dest, pkgname, langs): def run(args): options = parser.parse_args(args) subcmd = options.command - langs = options.langs.split('@@') + langs = options.langs.split('@@') if options.langs else None extra_args = options.extra_args.split('@@') subdir = os.environ.get('MESON_SUBDIR', options.subdir) src_sub = os.path.join(os.environ['MESON_SOURCE_ROOT'], subdir) bld_sub = os.path.join(os.environ['MESON_BUILD_ROOT'], subdir) + if not langs: + langs = read_linguas(src_sub) + if subcmd == 'pot': return run_potgen(src_sub, options.pkgname, options.datadirs, extra_args) elif subcmd == 'gen_gmo': |