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-11 14:59:56 -04:00
committed by Cole Robinson
parent 33d8bc9ae2
commit 61b75ba0fb
3 changed files with 15 additions and 55 deletions
+7 -47
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]]