[damned-lies] Fixes #109 - gettext.args Meson variable can be a list or a string



commit ee2b88cc6124920857a4b023743f140082360759
Author: Claude Paroz <claude 2xlibre net>
Date:   Tue Oct 9 19:22:20 2018 +0200

    Fixes #109 - gettext.args Meson variable can be a list or a string

 stats/models.py                           | 46 ++++++++++++++++---------------
 stats/tests/git/testmodule/po/meson.build |  4 +++
 stats/tests/tests.py                      |  8 ++++--
 3 files changed, 33 insertions(+), 25 deletions(-)
---
diff --git a/stats/models.py b/stats/models.py
index 823f1ff3..ae90b4cc 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -29,6 +29,28 @@ from stats.doap import update_doap_infos
 from people.models import Person
 from languages.models import Language
 
+# These args should be kept in sync with
+# https://github.com/mesonbuild/meson/blob/master/mesonbuild/modules/i18n.py#L25
+GLIB_PRESET = (
+    '--keyword=_',
+    '--keyword=N_',
+    '--keyword=C_:1c,2',
+    '--keyword=NC_:1c,2',
+    '--keyword=g_dcgettext:2',
+    '--keyword=g_dngettext:2,3',
+    '--keyword=g_dpgettext2:2c,3',
+
+    '--flag=N_:1:pass-c-format',
+    '--flag=C_:2:pass-c-format',
+    '--flag=NC_:2:pass-c-format',
+    '--flag=g_dngettext:2:pass-c-format',
+    '--flag=g_strdup_printf:1:c-format',
+    '--flag=g_string_printf:2:c-format',
+    '--flag=g_string_append_printf:2:c-format',
+    '--flag=g_error_new:3:c-format',
+    '--flag=g_set_error:4:c-format',
+)
+
 
 # Standard Django slug validation but also accept '+' (for gtk+)
 slug_re = re.compile(r'^[-\+a-zA-Z0-9_]+\Z')
@@ -803,30 +825,10 @@ class Domain(models.Model):
             makefile = utils.MakefileWrapper.find_file(branch, [vcs_path], file_name='meson.build')
             if makefile:
                 if makefile.read_variable('gettext.preset') == 'glib' or not makefile.readable:
-                    # These args should be kept in sync with
-                    # https://github.com/mesonbuild/meson/blob/master/mesonbuild/modules/i18n.py#L25
-                    pot_command.extend([
-                        '--keyword=_',
-                        '--keyword=N_',
-                        '--keyword=C_:1c,2',
-                        '--keyword=NC_:1c,2',
-                        '--keyword=g_dcgettext:2',
-                        '--keyword=g_dngettext:2,3',
-                        '--keyword=g_dpgettext2:2c,3',
-
-                        '--flag=N_:1:pass-c-format',
-                        '--flag=C_:2:pass-c-format',
-                        '--flag=NC_:2:pass-c-format',
-                        '--flag=g_dngettext:2:pass-c-format',
-                        '--flag=g_strdup_printf:1:c-format',
-                        '--flag=g_string_printf:2:c-format',
-                        '--flag=g_string_append_printf:2:c-format',
-                        '--flag=g_error_new:3:c-format',
-                        '--flag=g_set_error:4:c-format',
-                    ])
+                    pot_command.extend(GLIB_PRESET)
                 extra_args = makefile.read_variable('gettext.args')
                 if extra_args:
-                    pot_command.extend(extra_args)
+                    pot_command.extend([extra_args] if isinstance(extra_args, str) else extra_args)
                 datadirs = makefile.read_variable('gettext.data_dirs')
                 if datadirs:
                     env['GETTEXTDATADIRS'] = ':'.join(
diff --git a/stats/tests/git/testmodule/po/meson.build b/stats/tests/git/testmodule/po/meson.build
new file mode 100644
index 00000000..5a7309d8
--- /dev/null
+++ b/stats/tests/git/testmodule/po/meson.build
@@ -0,0 +1,4 @@
+i18n.gettext(meson.project_name(),
+  preset: 'glib',
+  args: '--keyword=Description'
+)
diff --git a/stats/tests/tests.py b/stats/tests/tests.py
index b0dd2c37..06d76f75 100644
--- a/stats/tests/tests.py
+++ b/stats/tests/tests.py
@@ -16,8 +16,8 @@ from django.test.utils import override_settings
 
 from common.utils import run_shell_command
 from stats.models import (
-    Module, Domain, Branch, Release, CategoryName, Statistics, FakeLangStatistics,
-    Information, UnableToCommit
+    GLIB_PRESET, Module, Domain, Branch, Release, CategoryName, Statistics,
+    FakeLangStatistics, Information, UnableToCommit
 )
 from stats import utils
 from languages.models import Language
@@ -526,7 +526,9 @@ class DomainTests(TestModuleBase):
             (['xgettext', '--files-from', 'POTFILES.in', '--directory',
              os.path.join(settings.SCRATCHDIR, 'git', 'testmodule'),
              '--from-code', 'utf-8',
-             '--add-comments', '--output', 'testmodule.pot', '--msgid-bugs-address',
+             '--add-comments', '--output', 'testmodule.pot'] + list(GLIB_PRESET) +
+             ['--keyword=Description',
+             '--msgid-bugs-address',
              'https://gitlab.gnome.org/GNOME/testmodule/issues'],
              {'GETTEXTDATADIRS': os.path.dirname(utils.ITS_DATA_DIR)}
             )


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]