21 def __init__(self, translationLocation, key_xml = False):
23 if os.path.exists(translationLocation):
24 for entry
in os.scandir(translationLocation):
25 if entry.name.endswith(
'.po')
and entry.is_file():
26 self.
parse_pot(os.path.join(translationLocation, entry.name))
29 if (os.path.exists(location)):
30 file = open(location,
"r", encoding=
"utf8")
33 if line.startswith(
"\"Language: "):
34 lang = line[len(
"\"Language: "):]
35 lang = lang.replace(
'\\n\"\n',
"")
37 file = open(location,
"r", encoding=
"utf8")
42 def addEntryToTranslationDict(key, entry, lang):
43 if len(entry.keys())>0:
47 text = entry.get(
"text",
"")
48 text = re.sub(
r"<.*?>",
" ", text)
49 key += str(re.sub(
r"\s+",
" ", text)).strip()
51 key += entry.get(
"text",
None)
56 dummyDict[lang] = entry
60 if line.isspace()
or len(line)<1:
61 addEntryToTranslationDict(key, entry, lang)
65 if line.startswith(
"msgid "):
66 string = line[len(
"msgid \""):]
67 string = string[:-len(
"\"\n")]
68 string = string.replace(
"\\\"",
"\"")
69 string = string.replace(
"\\\'",
"\'")
70 string = string.replace(
"\\#",
"#")
71 entry[
"text"] = string
73 if line.startswith(
"msgstr "):
74 string = line[len(
"msgstr \""):]
75 string = string[:-len(
"\"\n")]
76 string = string.replace(
"\\\"",
"\"")
77 string = string.replace(
"\\\'",
"\'")
78 string = string.replace(
"\\#",
"#")
79 entry[
"trans"] = string
81 if line.startswith(
"# "):
83 if "translComment" in entry.keys():
84 entry[
"translComment"] += line.replace(
"# ",
"")
86 entry[
"translComment"] = line.replace(
"# ",
"")
87 if line.startswith(
"#. "):
88 entry[
"extract"] = line.replace(
"#. ",
"")
89 if line.startswith(
"msgctxt "):
90 key = line[len(
"msgctxt \""):]
91 key = key[:-len(
"\"\n")]
93 if line.startswith(
"\"")
and len(multiLine)>0:
94 string = line[len(
"\""):]
95 string = string[:-len(
"\"\n")]
96 string = string.replace(
"\\\"",
"\"")
97 string = string.replace(
"\\\'",
"\'")
98 string = string.replace(
"\\#",
"#")
99 entry[multiLine] += string
101 addEntryToTranslationDict(key, entry, lang)