summaryrefslogtreecommitdiff
path: root/setup.py
diff options
context:
space:
mode:
authorPino Toscano <ptoscano@redhat.com>2020-07-08 16:54:13 +0200
committerCole Robinson <crobinso@redhat.com>2020-07-11 14:59:56 -0400
commitd306d7ef7c5ba4a4e1dfbfaecc62061ada99e0d6 (patch)
tree8967e201f5bab81fe6e4a65fc72c0eaf73cd7fdd /setup.py
parentfdc902e4614b3351867aedade15bb70525df55b7 (diff)
downloadvirt-manager-d306d7ef7c5ba4a4e1dfbfaecc62061ada99e0d6.tar.gz
setup: add a extract_messages command
Add a separate command to extract the messages; this also changes the way messages are extracted: - keep using intltool for desktop and AppStream files - use xgettext directly for Python sources, and UI files; this is way more flexible than intltool Reviewed-by: Cole Robinson <crobinso@redhat.com> Signed-off-by: Pino Toscano <ptoscano@redhat.com>
Diffstat (limited to 'setup.py')
-rwxr-xr-xsetup.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/setup.py b/setup.py
index 3e921b45..17ea4ef8 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,54 @@ 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 run(self):
+ bug_address = "https://github.com/virt-manager/virt-manager/issues"
+ xgettext_args = [
+ "xgettext",
+ "-F",
+ "--msgid-bugs-address=" + bug_address,
+ "-o", "po/virt-manager.pot",
+ "--package-name=virt-manager",
+ ]
+
+ # First extract the messages using intltool, so it creates the template
+ potpath = "po/POTFILES.in"
+ try:
+ potfiles = _generate_meta_potfiles_in()
+ open(potpath, "w").write(potfiles)
+ cmd = ["intltool-update", "-p", "-g", "virt-manager"]
+ wd = os.getcwd()
+ os.chdir("po")
+ self.spawn(cmd)
+ os.chdir(wd)
+ finally:
+ os.unlink(potpath)
+
+ # 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 + ["-j", "-L", "Python"] + py_sources
+ self.spawn(cmd)
+
+ # 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)
+
+
distutils.core.setup(
name="virt-manager",
version=BuildConfig.version,
@@ -754,6 +803,8 @@ distutils.core.setup(
'test_urls': TestURLFetch,
'test_initrd_inject': TestInitrdInject,
'test_dist': TestDist,
+
+ 'extract_messages': ExtractMessages,
},
distclass=VMMDistribution,