Repository: mesonbuild/meson

Issue:
i18n: allow to use keywords in i18n.merge_file()
It needed for libpeas-based plugin systems and another plugin systems, which relies on keyfile-based configs.


Discussion:
Something like #1630 

Resolving patch:
diff --git a/mesonbuild/modules/i18n.py b/mesonbuild/modules/i18n.py
--- a/mesonbuild/modules/i18n.py
+++ b/mesonbuild/modules/i18n.py
@@ -64,7 +64,8 @@ def _get_data_dirs(state, dirs):
         return [path.join(src_dir, d) for d in dirs]
 
     @FeatureNew('i18n.merge_file', '0.37.0')
-    @permittedKwargs(build.CustomTarget.known_kwargs | {'data_dirs', 'po_dir', 'type'})
+    @FeatureNewKwargs('i18n.merge_file', '0.51.0', ['args'])
+    @permittedKwargs(build.CustomTarget.known_kwargs | {'data_dirs', 'po_dir', 'type', 'args'})
     def merge_file(self, state, args, kwargs):
         podir = kwargs.pop('po_dir', None)
         if not podir:
@@ -86,6 +87,10 @@ def merge_file(self, state, args, kwargs):
         if datadirs:
             command.append(datadirs)
 
+        if 'args' in kwargs:
+            command.append('--')
+            command.append(mesonlib.stringlistify(kwargs.pop('args', [])))
+
         kwargs['command'] = command
 
         inputfile = kwargs['input']
diff --git a/mesonbuild/scripts/msgfmthelper.py b/mesonbuild/scripts/msgfmthelper.py
--- a/mesonbuild/scripts/msgfmthelper.py
+++ b/mesonbuild/scripts/msgfmthelper.py
@@ -22,6 +22,7 @@
 parser.add_argument('type')
 parser.add_argument('podir')
 parser.add_argument('--datadirs', default='')
+parser.add_argument('args', default=[], metavar='extra msgfmt argument', nargs='*')
 
 
 def run(args):
@@ -31,5 +32,5 @@ def run(args):
         env = os.environ.copy()
         env.update({'GETTEXTDATADIRS': options.datadirs})
     return subprocess.call(['msgfmt', '--' + options.type, '-d', options.podir,
-                            '--template', options.input,  '-o', options.output],
+                            '--template', options.input,  '-o', options.output] + options.args,
                            env=env)


Test patch:
diff --git a/test cases/frameworks/6 gettext/data2/meson.build b/test cases/frameworks/6 gettext/data2/meson.build
--- a/test cases/frameworks/6 gettext/data2/meson.build	
+++ b/test cases/frameworks/6 gettext/data2/meson.build	
@@ -1,8 +1,9 @@
 i18n.merge_file(
   input: 'test.desktop.in',
-  output: 'test.desktop',
+  output: 'test.plugin',
   type: 'desktop',
   po_dir: '../po',
+  args: ['--keyword=Description'],
   install: true,
   install_dir: join_paths(get_option('datadir'), 'applications')
 )
diff --git a/test cases/frameworks/6 gettext/data2/test.desktop.in b/test cases/frameworks/6 gettext/data2/test.desktop.in
--- a/test cases/frameworks/6 gettext/data2/test.desktop.in	
+++ b/test cases/frameworks/6 gettext/data2/test.desktop.in	
@@ -1,6 +1,6 @@
 [Desktop Entry]
 Name=Test
 GenericName=Application
-Comment=Test Application
+Description=Test Application
 Type=Application
 
diff --git a/test cases/frameworks/6 gettext/installed_files.txt b/test cases/frameworks/6 gettext/installed_files.txt
--- a/test cases/frameworks/6 gettext/installed_files.txt	
+++ b/test cases/frameworks/6 gettext/installed_files.txt	
@@ -1,8 +1,10 @@
 usr/bin/intlprog?exe
 usr/share/locale/de/LC_MESSAGES/intltest.mo
 usr/share/locale/fi/LC_MESSAGES/intltest.mo
+usr/share/locale/ru/LC_MESSAGES/intltest.mo
 usr/share/applications/something.desktop
 usr/share/applications/test.desktop
+usr/share/applications/test.plugin
 usr/share/applications/test2.desktop
 usr/share/applications/test3.desktop
 usr/share/applications/test4.desktop
diff --git a/test cases/frameworks/6 gettext/po/LINGUAS b/test cases/frameworks/6 gettext/po/LINGUAS
--- a/test cases/frameworks/6 gettext/po/LINGUAS	
+++ b/test cases/frameworks/6 gettext/po/LINGUAS	
@@ -1,2 +1,4 @@
 de
 fi
+ru
+
diff --git a/test cases/frameworks/6 gettext/po/meson.build b/test cases/frameworks/6 gettext/po/meson.build
--- a/test cases/frameworks/6 gettext/po/meson.build	
+++ b/test cases/frameworks/6 gettext/po/meson.build	
@@ -1,3 +1,3 @@
-langs = ['fi', 'de']
+langs = ['fi', 'de', 'ru']
 
 i18n.gettext('intltest', languages : langs)
diff --git a/test cases/frameworks/6 gettext/po/ru.po b/test cases/frameworks/6 gettext/po/ru.po
new file mode 100644
--- /dev/null
+++ b/test cases/frameworks/6 gettext/po/ru.po	
@@ -0,0 +1,34 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the intltest package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: intltest\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2017-05-31 05:16-0500\n"
+"PO-Revision-Date: 2019-04-22 02:38+0300\n"
+"Language: ru\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Last-Translator: \n"
+"Language-Team: \n"
+"X-Generator: Poedit 2.2.1\n"
+
+#: src/intlmain.c:15
+msgid "International greeting."
+msgstr "Межнациональное приветствие."
+
+#: data/test.desktop.in:3
+msgid "Test"
+msgstr "Тест"
+
+#: data/test.desktop.in:4
+msgid "Application"
+msgstr "Приложение"
+
+#: data/test.desktop.in:5
+msgid "Test Application"
+msgstr "Тестовое приложение"