[virt-manager PATCH v3 5/8] Handle AppStream files using gettext

Pino Toscano ptoscano at redhat.com
Wed Jul 8 06:54:51 UTC 2020


Starting from version 0.19.6, gettext has native capabilities to extract
from, and merge back translations in AppStream files.

Hence, use xgettext to extract messages, and msgfmt to create AppStream
files with translations; this requires to change the keys in AppStream
files to be prefixed with underscore anymore.
(The LINGUAS file in the meta-po subdirectory, needed otherwise msgfmt
does not recognize the directory as containing translations, is already
there.)

Update the gettext required version in INSTALL.md.

Signed-off-by: Pino Toscano <ptoscano at redhat.com>
---
 INSTALL.md                       |  2 +-
 data/virt-manager.appdata.xml.in | 14 ++++-----
 setup.py                         | 51 ++++----------------------------
 3 files changed, 13 insertions(+), 54 deletions(-)

diff --git a/INSTALL.md b/INSTALL.md
index dbc3ebde..a12320f6 100644
--- a/INSTALL.md
+++ b/INSTALL.md
@@ -30,7 +30,7 @@ A detailed dependency list can be found in
 
 Minimum version requirements of major components:
 
-   - gettext >= 0.19
+   - gettext >= 0.19.6
    - python >= 3.4
    - gtk3 >= 3.22
    - libvirt-python >= 0.6.0
diff --git a/data/virt-manager.appdata.xml.in b/data/virt-manager.appdata.xml.in
index 65b6ae58..caac4518 100644
--- a/data/virt-manager.appdata.xml.in
+++ b/data/virt-manager.appdata.xml.in
@@ -3,29 +3,29 @@
   <id>virt-manager.desktop</id>
   <metadata_license>CC0-1.0</metadata_license>
   <project_license>GPL-2.0+</project_license>
-  <_name>Virtual Machine Manager</_name>
-  <_summary>Graphically manage KVM, Xen, or LXC via libvirt</_summary>
+  <name>Virtual Machine Manager</name>
+  <summary>Graphically manage KVM, Xen, or LXC via libvirt</summary>
   <description>
-    <_p>
+    <p>
    Virtual Machine Manager provides a graphical tool for administering virtual
    machines for KVM, Xen, and LXC. Start, stop, add or remove virtual devices,
    connect to a graphical or serial console, and see resource usage statistics
    for existing VMs on local or remote machines. Uses libvirt as the backend
    management API.
-  </_p>
+  </p>
   </description>
   <screenshots>
     <screenshot type="default">
       <image>https://virt-manager.org/appdata/en_US/manager.png</image>
-      <_caption>Main manager window</_caption>
+      <caption>Main manager window</caption>
     </screenshot>
     <screenshot>
       <image>https://virt-manager.org/appdata/en_US/details.png</image>
-      <_caption>Virtual machine configuration screen</_caption>
+      <caption>Virtual machine configuration screen</caption>
     </screenshot>
     <screenshot>
       <image>https://virt-manager.org/appdata/en_US/console.png</image>
-      <_caption>Graphical console connection for a virtual machine</_caption>
+      <caption>Graphical console connection for a virtual machine</caption>
     </screenshot>
   </screenshots>
   <url type="homepage">https://www.virt-manager.org/</url>
diff --git a/setup.py b/setup.py
index 95e7b16e..54a2481e 100755
--- a/setup.py
+++ b/setup.py
@@ -60,13 +60,6 @@ _appdata_files = [
 ]
 
 
-def _generate_meta_potfiles_in():
-    potfiles = ""
-    for ignore, filelist in _appdata_files:
-        potfiles += "\n".join(filelist) + "\n"
-    return potfiles
-
-
 class my_build_i18n(distutils.command.build.build):
     """
     Add our desktop files to the list, saves us having to track setup.cfg
@@ -119,7 +112,8 @@ class my_build_i18n(distutils.command.build.build):
                 max_po_mtime = po_mtime
 
         # merge .in with translations using gettext
-        for (file_set, switch) in [(_desktop_files, "--desktop")]:
+        for (file_set, switch) in [(_appdata_files, "--xml"),
+                                   (_desktop_files, "--desktop")]:
             for (target, files) in file_set:
                 build_target = os.path.join("build", target)
                 if not os.path.exists(build_target):
@@ -145,33 +139,6 @@ class my_build_i18n(distutils.command.build.build):
                     files_merged.append(file_merged)
                 self.distribution.data_files.append((target, files_merged))
 
-        # merge .in with translation
-        for (file_set, switch) in [(_appdata_files, "-x")]:
-            for (target, files) in file_set:
-                build_target = os.path.join("build", target)
-                if not os.path.exists(build_target):
-                    os.makedirs(build_target)
-
-                files_merged = []
-                for f in files:
-                    if f.endswith(".in"):
-                        file_merged = os.path.basename(f[:-3])
-                    else:
-                        file_merged = os.path.basename(f)
-
-                    file_merged = os.path.join(build_target, file_merged)
-                    cmd = ["intltool-merge", switch, po_dir, f,
-                           file_merged]
-                    mtime_merged = (os.path.exists(file_merged) and
-                                    os.path.getmtime(file_merged)) or 0
-                    mtime_file = os.path.getmtime(f)
-                    if (mtime_merged < max_po_mtime or
-                        mtime_merged < mtime_file):
-                        # Only build if output is older than input (.po,.in)
-                        self.spawn(cmd)
-                    files_merged.append(file_merged)
-                self.distribution.data_files.append((target, files_merged))
-
 
 class my_build(distutils.command.build.build):
     """
@@ -727,23 +694,15 @@ class ExtractMessages(distutils.core.Command):
 
     def _extract_meta(self):
         po_dir = "meta-po"
-        potfiles = _generate_meta_potfiles_in()
-        potpath = "meta-po/POTFILES.in"
         pot_file = os.path.join(po_dir, "virt-manager-meta.pot")
 
         xgettext_args = self.common_xgettext_args + \
                         ["-o", pot_file, "--package-name=virt-manager-meta"]
 
         # First extract the messages from the AppStream sources
-        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)
+        appdata_files = [f for sublist in _appdata_files for f in sublist[1]]
+        cmd = xgettext_args + appdata_files
+        self.spawn(cmd)
 
         # Then extract the messages from the desktop files
         desktop_files = [f for sublist in _desktop_files for f in sublist[1]]
-- 
2.26.2




More information about the virt-tools-list mailing list