From 06fdabb7ac1834823c6ecc4bebb94b13da5cf03e Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Fri, 18 Aug 2017 15:22:37 +0100 Subject: Support LINGUAS for gnome.yelp() languages Listing all languages inside meson.build for the Yelp-based manual localisation is error-prone, and it also requires parsing and modifying Meson files from external tools. Just like we do for i18n, we can use an ancillary `LINGUAS` file in the help source sub-directory to list all the help languages. --- mesonbuild/scripts/yelphelper.py | 19 +++++++++++++++++++ test cases/frameworks/13 yelp/help/LINGUAS | 2 ++ test cases/frameworks/13 yelp/help/meson.build | 6 ++++++ test cases/frameworks/13 yelp/installed_files.txt | 6 ++++++ 4 files changed, 33 insertions(+) create mode 100644 test cases/frameworks/13 yelp/help/LINGUAS diff --git a/mesonbuild/scripts/yelphelper.py b/mesonbuild/scripts/yelphelper.py index 978a870..f8c9f8c 100644 --- a/mesonbuild/scripts/yelphelper.py +++ b/mesonbuild/scripts/yelphelper.py @@ -29,6 +29,22 @@ parser.add_argument('--media', dest='media', default='') parser.add_argument('--langs', dest='langs', default='') parser.add_argument('--symlinks', type=bool, dest='symlinks', default=False) +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 build_pot(srcdir, project_id, sources): # Must be relative paths sources = [os.path.join('C', source) for source in sources] @@ -108,6 +124,9 @@ def run(args): build_subdir = os.path.join(os.environ['MESON_BUILD_ROOT'], options.subdir) abs_sources = [os.path.join(src_subdir, 'C', source) for source in sources] + if not langs: + langs = read_linguas(src_subdir) + if options.command == 'pot': build_pot(src_subdir, options.project_id, sources) elif options.command == 'update-po': diff --git a/test cases/frameworks/13 yelp/help/LINGUAS b/test cases/frameworks/13 yelp/help/LINGUAS new file mode 100644 index 0000000..173f978 --- /dev/null +++ b/test cases/frameworks/13 yelp/help/LINGUAS @@ -0,0 +1,2 @@ +de +es diff --git a/test cases/frameworks/13 yelp/help/meson.build b/test cases/frameworks/13 yelp/help/meson.build index 85bc980..c8edd61 100644 --- a/test cases/frameworks/13 yelp/help/meson.build +++ b/test cases/frameworks/13 yelp/help/meson.build @@ -13,3 +13,9 @@ gnome.yelp('meson-symlink', symlink_media: true, languages: ['de', 'es'], ) + +gnome.yelp('meson-linguas', + sources: 'index.page', + media: 'media/test.txt', + symlink_media: false, +) diff --git a/test cases/frameworks/13 yelp/installed_files.txt b/test cases/frameworks/13 yelp/installed_files.txt index 9fc097d..1f6522f 100644 --- a/test cases/frameworks/13 yelp/installed_files.txt +++ b/test cases/frameworks/13 yelp/installed_files.txt @@ -10,3 +10,9 @@ usr/share/help/es/meson-symlink/media/test.txt usr/share/help/es/meson-symlink/index.page usr/share/help/de/meson-symlink/index.page usr/share/help/de/meson-symlink/media/test.txt +usr/share/help/C/meson-linguas/index.page +usr/share/help/C/meson-linguas/media/test.txt +usr/share/help/es/meson-linguas/media/test.txt +usr/share/help/es/meson-linguas/index.page +usr/share/help/de/meson-linguas/index.page +usr/share/help/de/meson-linguas/media/test.txt -- cgit v1.1 From 0545228fddf724461bd6287e6c42d67a1eedeb83 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Fri, 18 Aug 2017 19:06:22 +0100 Subject: Re-use gettext.read_linguas in yelphelper --- mesonbuild/scripts/yelphelper.py | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/mesonbuild/scripts/yelphelper.py b/mesonbuild/scripts/yelphelper.py index f8c9f8c..ab99267 100644 --- a/mesonbuild/scripts/yelphelper.py +++ b/mesonbuild/scripts/yelphelper.py @@ -18,6 +18,7 @@ import shutil import argparse from .. import mlog from . import destdir_join +from .gettext import read_linguas parser = argparse.ArgumentParser() parser.add_argument('command') @@ -29,22 +30,6 @@ parser.add_argument('--media', dest='media', default='') parser.add_argument('--langs', dest='langs', default='') parser.add_argument('--symlinks', type=bool, dest='symlinks', default=False) -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 build_pot(srcdir, project_id, sources): # Must be relative paths sources = [os.path.join('C', source) for source in sources] -- cgit v1.1 From 6f1d7e3d0ab541e8f98f7b45551fc8819618c20d Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Tue, 12 Sep 2017 21:45:04 +0100 Subject: Add deprecation warning for gnome.yelp() argument The 'languages' argument is deprecated; the LINGUAS file supercedes it as the canonical source of translations. --- mesonbuild/modules/gnome.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index 43c4881..f90f919 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -651,6 +651,11 @@ class GnomeModule(ExtensionModule): source_str = '@@'.join(sources) langs = mesonlib.stringlistify(kwargs.pop('languages', [])) + if langs: + mlog.log(mlog.red('DEPRECATION:'), '''The "languages" argument of gnome.yelp() is deprecated. +Use a LINGUAS file in the sources directory instead. +This will become a hard error in the future.''') + media = mesonlib.stringlistify(kwargs.pop('media', [])) symlinks = kwargs.pop('symlink_media', True) -- cgit v1.1