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 /mesonbuild/scripts/gettext.py | |
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
Diffstat (limited to 'mesonbuild/scripts/gettext.py')
-rw-r--r-- | mesonbuild/scripts/gettext.py | 21 |
1 files changed, 20 insertions, 1 deletions
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': |