summaryrefslogtreecommitdiff
path: root/setup.py
diff options
context:
space:
mode:
authorPino Toscano <ptoscano@redhat.com>2020-07-08 16:54:16 +0200
committerCole Robinson <crobinso@redhat.com>2020-07-11 14:59:56 -0400
commit33d8bc9ae2e9f8f27955e0b5cf460f89fb381ea4 (patch)
treee6cbe559256e3bb659ce004dfbc4dcc6ea62274d /setup.py
parent69a1f5dbc19dd3780343da2741e8165ef86d05af (diff)
downloadvirt-manager-33d8bc9ae2e9f8f27955e0b5cf460f89fb381ea4.tar.gz
Handle desktop files using gettext
Starting from version 0.19, gettext has native capabilities to extract from, and merge back translations in desktop files. Hence, use xgettext to extract messages, and msgfmt to create a desktop file with translations; because of this, there no more need to prefix with underscore the keys 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>
Diffstat (limited to 'setup.py')
-rwxr-xr-xsetup.py37
1 files changed, 34 insertions, 3 deletions
diff --git a/setup.py b/setup.py
index 95d9a7a1..34532e12 100755
--- a/setup.py
+++ b/setup.py
@@ -61,7 +61,7 @@ _appdata_files = [
def _generate_meta_potfiles_in():
potfiles = ""
- for ignore, filelist in _desktop_files + _appdata_files:
+ for ignore, filelist in _appdata_files:
potfiles += "\n".join(filelist) + "\n"
return potfiles
@@ -107,9 +107,35 @@ class my_build_i18n(distutils.command.build.build):
targetpath = os.path.join("share/locale", lang, "LC_MESSAGES")
self.distribution.data_files.append((targetpath, (mo_file,)))
+ # Merge .in with translations using gettext
+ for (file_set, switch) in [(_desktop_files, "--desktop")]:
+ 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 = ["msgfmt", switch, "--template", f, "-d", po_dir,
+ "-o", 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))
+
# merge .in with translation
- for (file_set, switch) in [(_desktop_files, "-d"),
- (_appdata_files, "-x")]:
+ 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):
@@ -685,6 +711,11 @@ class ExtractMessages(distutils.core.Command):
finally:
os.unlink(potpath)
+ # Extract the messages from the desktop files
+ desktop_files = [f for sublist in _desktop_files for f in sublist[1]]
+ cmd = xgettext_args + ["-j", "-L", "Desktop"] + desktop_files
+ self.spawn(cmd)
+
# Extract the messages from the Python sources
py_sources = list(Path("virtManager").rglob("*.py"))
py_sources += list(Path("virtinst").rglob("*.py"))