[virt-manager PATCH v3 2/8] setup: add a extract_messages command
Pino Toscano
ptoscano at redhat.com
Wed Jul 8 06:54:48 UTC 2020
Add a separate command to extract the messages; this also changes the
way messages are extracted:
- the messages from the application itself are still extracted to a
virt-manager catalog; use xgettext instead of intltool, as it is
simpler and more flexible
- the messages from the .in files are extracted to a separate
virt-manager-meta catalog in a separate directory; this will ease the
merge back, and avoid shipping these helper translations
Signed-off-by: Pino Toscano <ptoscano at redhat.com>
---
setup.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)
diff --git a/setup.py b/setup.py
index 3e921b45..7bc1e3a6 100755
--- a/setup.py
+++ b/setup.py
@@ -12,6 +12,7 @@ if sys.version_info.major < 3:
import glob
import fnmatch
import os
+from pathlib import Path
import unittest
import distutils
@@ -690,6 +691,63 @@ class VMMDistribution(distutils.dist.Distribution):
distutils.dist.Distribution.__init__(self, *args, **kwargs)
+class ExtractMessages(distutils.core.Command):
+ user_options = [
+ ]
+ description = "Extract the translation messages"
+
+ bug_address = "https://github.com/virt-manager/virt-manager/issues"
+ common_xgettext_args = [
+ "xgettext",
+ "-F",
+ "--msgid-bugs-address=" + bug_address
+ ]
+
+ def initialize_options(self):
+ pass
+
+ def finalize_options(self):
+ pass
+
+ def _extract_main(self):
+ pot_file = "po/virt-manager.pot"
+
+ xgettext_args = self.common_xgettext_args + \
+ ["-o", pot_file, "--package-name=virt-manager"]
+
+ # First extract the messages from the Python sources
+ py_sources = list(Path("virtManager").rglob("*.py"))
+ py_sources += list(Path("virtinst").rglob("*.py"))
+ py_sources = [str(src) for src in py_sources]
+ cmd = xgettext_args + ["-L", "Python"] + py_sources
+ self.spawn(cmd)
+
+ # Then extract the messages from the Glade UI files
+ ui_files = list(Path(".").rglob("*.ui"))
+ ui_files = [str(src) for src in ui_files]
+ cmd = xgettext_args + ["-j", "-L", "Glade"] + ui_files
+ self.spawn(cmd)
+
+ def _extract_meta(self):
+ po_dir = "meta-po"
+ potfiles = _generate_meta_potfiles_in()
+ potpath = "meta-po/POTFILES.in"
+
+ try:
+ open(potpath, "w").write(potfiles)
+ cmd = ["intltool-update", "-p", "-g", "virt-manager-meta"]
+ wd = os.getcwd()
+ os.chdir(po_dir)
+ self.spawn(cmd)
+ os.chdir(wd)
+ finally:
+ os.unlink(potpath)
+
+ def run(self):
+ self._extract_main()
+ self._extract_meta()
+
+
distutils.core.setup(
name="virt-manager",
version=BuildConfig.version,
@@ -754,6 +812,8 @@ distutils.core.setup(
'test_urls': TestURLFetch,
'test_initrd_inject': TestInitrdInject,
'test_dist': TestDist,
+
+ 'extract_messages': ExtractMessages,
},
distclass=VMMDistribution,
--
2.26.2
More information about the virt-tools-list
mailing list