[virt-manager PATCH v2 2/5] setup: add a extract_messages command

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

 



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 intltools, 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@xxxxxxxxxx>
---
 setup.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/setup.py b/setup.py
index 3e921b45..b75c1417 100755
--- a/setup.py
+++ b/setup.py
@@ -690,6 +690,56 @@ class VMMDistribution(distutils.dist.Distribution):
         distutils.dist.Distribution.__init__(self, *args, **kwargs)
 
 
+class ExtractMessages(distutils.core.Command):
+    user_options = [
+    ]
+    description = "Extract the translation messages"
+
+    def initialize_options(self):
+        pass
+
+    def finalize_options(self):
+        pass
+
+    def _extract_main(self):
+        pot_file = "po/virt-manager.pot"
+        bug_address = "https://github.com/virt-manager/virt-manager/issues";
+
+        common_xgettext_args = ["xgettext", "-o", pot_file, "-F",
+                                "--package-name=virt-manager",
+                                "--msgid-bugs-address=" + bug_address]
+
+        # First extract the messages from the Python sources
+        py_sources = glob.glob("virtManager/**/*.py", recursive=True)
+        py_sources += glob.glob("virtinst/**/*.py", recursive=True)
+        cmd = common_xgettext_args + ["-L", "Python"] + py_sources
+        self.spawn(cmd)
+
+        # Then extract the messages from the Glade UI files
+        ui_files = glob.glob("**/*.ui", recursive=True)
+        cmd = common_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 +804,8 @@ distutils.core.setup(
         'test_urls': TestURLFetch,
         'test_initrd_inject': TestInitrdInject,
         'test_dist': TestDist,
+
+        'extract_messages': ExtractMessages,
     },
 
     distclass=VMMDistribution,
-- 
2.26.2




[Index of Archives]     [Linux Virtualization]     [KVM Development]     [CentOS Virtualization]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]     [Video 4 Linux]

  Powered by Linux