-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdump_translations_to_desktopentries.py
executable file
·55 lines (41 loc) · 1.34 KB
/
dump_translations_to_desktopentries.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/python3
# -*- coding: utf-8 -*
"""
This script dumps translated strings from po files to the modules'
desktop entries.
"""
import os
import polib
from xdg.DesktopEntry import DesktopEntry
class TranslationCatalog:
languages = {}
def __init__(self, source_dir):
"""
Initializes the class.
"""
for translation in os.listdir(source_dir):
if translation.endswith(".po"):
language = translation.replace(".po","")
self.languages[language] = polib.pofile(os.path.join(source_dir, translation))
catalog = TranslationCatalog("./po/vera-control-center")
# Search for desktop files
desktop_files = []
for directory, dirnames, filenames in os.walk("."):
for file_ in filenames:
if file_.endswith(".desktop"):
entry = DesktopEntry(os.path.join(directory, file_))
for key in ("Name", "Comment", "Keywords"):
try:
source = entry.get(key)
except:
continue
for lang, obj in TranslationCatalog.languages.items():
found = obj.find(source)
if found and found.msgstr != "":
# xdg's IniFile supports the locale= keyword,
# but it supports only a boolean value. The locale
# is hardcoded to the one of the current system.
# We workaround this by specifying the right key
# right now.
entry.set("%s[%s]" % (key, lang), found.msgstr)
entry.write()