From 61b75ba0fb0e582807efb1e080fe7dab8ec6da43 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Wed, 8 Jul 2020 16:54:17 +0200 Subject: [PATCH] Handle AppStream files using gettext 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. Reviewed-by: Cole Robinson Signed-off-by: Pino Toscano --- 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 @@ virt-manager.desktop CC0-1.0 GPL-2.0+ - <_name>Virtual Machine Manager - <_summary>Graphically manage KVM, Xen, or LXC via libvirt + Virtual Machine Manager + Graphically manage KVM, Xen, or LXC via libvirt - <_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. - +

https://virt-manager.org/appdata/en_US/manager.png - <_caption>Main manager window + Main manager window https://virt-manager.org/appdata/en_US/details.png - <_caption>Virtual machine configuration screen + Virtual machine configuration screen https://virt-manager.org/appdata/en_US/console.png - <_caption>Graphical console connection for a virtual machine + Graphical console connection for a virtual machine https://www.virt-manager.org/ diff --git a/setup.py b/setup.py index 34532e12..4382d6af 100755 --- a/setup.py +++ b/setup.py @@ -59,13 +59,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 @@ -108,7 +101,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): @@ -134,33 +128,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): """ @@ -698,18 +665,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]]