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 <crobinso@redhat.com>
Signed-off-by: Pino Toscano <ptoscano@redhat.com>
This commit is contained in:
Pino Toscano 2020-07-08 16:54:17 +02:00 committed by Cole Robinson
parent 33d8bc9ae2
commit 61b75ba0fb
3 changed files with 15 additions and 55 deletions

View File

@ -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

View File

@ -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>

View File

@ -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]]