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. Signed-off-by: Pino Toscano <ptoscano@xxxxxxxxxx> --- INSTALL.md | 2 +- data/virt-manager.desktop.in | 4 ++-- setup.py | 37 +++++++++++++++++++++++++++++++++--- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 7080fce8..dbc3ebde 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 + - gettext >= 0.19 - python >= 3.4 - gtk3 >= 3.22 - libvirt-python >= 0.6.0 diff --git a/data/virt-manager.desktop.in b/data/virt-manager.desktop.in index 33765ec3..41cc26a1 100644 --- a/data/virt-manager.desktop.in +++ b/data/virt-manager.desktop.in @@ -1,6 +1,6 @@ [Desktop Entry] -_Name=Virtual Machine Manager -_Comment=Manage virtual machines +Name=Virtual Machine Manager +Comment=Manage virtual machines Icon=virt-manager Exec=virt-manager Type=Application diff --git a/setup.py b/setup.py index 25bc5cf3..79e9f327 100755 --- a/setup.py +++ b/setup.py @@ -62,7 +62,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 @@ -108,9 +108,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): @@ -686,6 +712,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")) -- 2.26.2