[virt-manager PATCH v4 6/9] Handle AppStream files using gettext

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

 



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; because of this, there no more need to prefix
with underscore the tags to be translated.

Update the gettext required version in INSTALL.md.

Signed-off-by: Pino Toscano <ptoscano@xxxxxxxxxx>
---
 INSTALL.md                       |  2 +-
 data/virt-manager.appdata.xml.in | 14 ++++-----
 setup.py                         | 54 +++++---------------------------
 3 files changed, 15 insertions(+), 55 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 79e9f327..808d72bb 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
@@ -109,7 +102,8 @@ class my_build_i18n(distutils.command.build.build):
             self.distribution.data_files.append((targetpath, (mo_file,)))
 
         # 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):
@@ -135,33 +129,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):
     """
@@ -699,18 +666,11 @@ class ExtractMessages(distutils.core.Command):
             "--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)
+        # First extract the messages from the AppStream sources,
+        # creating the template
+        appdata_files = [f for sublist in _appdata_files for f in sublist[1]]
+        cmd = xgettext_args + appdata_files
+        self.spawn(cmd)
 
         # Extract the messages from the desktop files
         desktop_files = [f for sublist in _desktop_files for f in sublist[1]]
-- 
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