mirror of
https://github.com/virt-manager/virt-manager.git
synced 2024-12-22 13:34:07 +03:00
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>
This commit is contained in:
parent
69a1f5dbc1
commit
33d8bc9ae2
@ -30,7 +30,7 @@ A detailed dependency list can be found in
|
|||||||
|
|
||||||
Minimum version requirements of major components:
|
Minimum version requirements of major components:
|
||||||
|
|
||||||
- gettext
|
- gettext >= 0.19
|
||||||
- python >= 3.4
|
- python >= 3.4
|
||||||
- gtk3 >= 3.22
|
- gtk3 >= 3.22
|
||||||
- libvirt-python >= 0.6.0
|
- libvirt-python >= 0.6.0
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[Desktop Entry]
|
[Desktop Entry]
|
||||||
_Name=Virtual Machine Manager
|
Name=Virtual Machine Manager
|
||||||
_Comment=Manage virtual machines
|
Comment=Manage virtual machines
|
||||||
Icon=virt-manager
|
Icon=virt-manager
|
||||||
Exec=virt-manager
|
Exec=virt-manager
|
||||||
Type=Application
|
Type=Application
|
||||||
|
37
setup.py
37
setup.py
@ -61,7 +61,7 @@ _appdata_files = [
|
|||||||
|
|
||||||
def _generate_meta_potfiles_in():
|
def _generate_meta_potfiles_in():
|
||||||
potfiles = ""
|
potfiles = ""
|
||||||
for ignore, filelist in _desktop_files + _appdata_files:
|
for ignore, filelist in _appdata_files:
|
||||||
potfiles += "\n".join(filelist) + "\n"
|
potfiles += "\n".join(filelist) + "\n"
|
||||||
return potfiles
|
return potfiles
|
||||||
|
|
||||||
@ -107,9 +107,35 @@ class my_build_i18n(distutils.command.build.build):
|
|||||||
targetpath = os.path.join("share/locale", lang, "LC_MESSAGES")
|
targetpath = os.path.join("share/locale", lang, "LC_MESSAGES")
|
||||||
self.distribution.data_files.append((targetpath, (mo_file,)))
|
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
|
# merge .in with translation
|
||||||
for (file_set, switch) in [(_desktop_files, "-d"),
|
for (file_set, switch) in [(_appdata_files, "-x")]:
|
||||||
(_appdata_files, "-x")]:
|
|
||||||
for (target, files) in file_set:
|
for (target, files) in file_set:
|
||||||
build_target = os.path.join("build", target)
|
build_target = os.path.join("build", target)
|
||||||
if not os.path.exists(build_target):
|
if not os.path.exists(build_target):
|
||||||
@ -685,6 +711,11 @@ class ExtractMessages(distutils.core.Command):
|
|||||||
finally:
|
finally:
|
||||||
os.unlink(potpath)
|
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
|
# Extract the messages from the Python sources
|
||||||
py_sources = list(Path("virtManager").rglob("*.py"))
|
py_sources = list(Path("virtManager").rglob("*.py"))
|
||||||
py_sources += list(Path("virtinst").rglob("*.py"))
|
py_sources += list(Path("virtinst").rglob("*.py"))
|
||||||
|
Loading…
Reference in New Issue
Block a user