60 if (os.path.exists(location)):
61 file = open(location,
"r", newline=
"", encoding=
"utf8")
66 def addEntryToTranslationDict(key, entry):
67 if len(entry.keys()) > 0:
69 key = entry.get(
"text",
None)
74 for line
in file
or len(line) < 1:
76 addEntryToTranslationDict(key, entry)
80 if line.startswith(
"msgid "):
81 string = line.strip(
"msgid \"")
82 string = string[:-len(
'"\n')]
83 string = string.replace(
"\\\"",
"\"")
84 string = string.replace(
"\\\'",
"\'")
85 string = string.replace(
"\\#",
"#")
86 entry[
"text"] = string
88 if line.startswith(
"msgstr "):
89 string = line.strip(
"msgstr \"")
90 string = string[:-len(
'"\n')]
91 string = string.replace(
"\\\"",
"\"")
92 string = string.replace(
"\\\'",
"\'")
93 string = string.replace(
"\\#",
"#")
94 entry[
"trans"] = string
96 if line.startswith(
"# "):
98 entry[
"translator"] = line
99 if line.startswith(
"#. "):
100 entry[
"extract"] = line
101 if line.startswith(
"msgctxt "):
102 string = line.strip(
"msgctxt \"")
103 string = string[:-len(
'"\n')]
104 string = string.replace(
"\\\"",
"\"")
105 string = string.replace(
"\\\'",
"\'")
106 string = string.replace(
"\\#",
"#")
108 if line.startswith(
"\"")
and len(multiLine) > 0:
110 string = string[:-len(
'"\n')]
111 string = string.replace(
"\\\"",
"\"")
112 string = string.replace(
"\\\'",
"\'")
113 string = string.replace(
"\\#",
"#")
114 entry[multiLine] += string
115 addEntryToTranslationDict(key, entry)
119 page = zipfile.ZipFile(location,
"a")
120 xmlroot = minidom.parseString(page.read(
"maindoc.xml"))
121 doc = xmlroot.documentElement
125 for member
in page.namelist():
126 info = page.getinfo(member)
127 if info.filename.endswith(
'svg'):
128 candidates.append(info.filename)
130 def parseThroughChildNodes(node):
131 for childNode
in node.childNodes:
132 if childNode.nodeType != minidom.Node.TEXT_NODE:
133 if childNode.tagName ==
"layer" and childNode.getAttribute(
"nodetype") ==
"shapelayer":
136 if t
in childNode.getAttribute(
"name"):
139 filename = childNode.getAttribute(
"filename")
141 if str(filename +
".shapelayer/content.svg")
in c:
143 if childNode.childNodes:
144 parseThroughChildNodes(childNode)
146 parseThroughChildNodes(doc)
149 xmlroot = minidom.parseString(page.read(
"documentinfo.xml"))
151 def parseThroughDocumentInfo(node, dict):
152 for childNode
in node.childNodes:
153 if childNode.nodeType != minidom.Node.TEXT_NODE
and childNode.nodeType != minidom.Node.CDATA_SECTION_NODE:
154 if childNode.tagName ==
"title":
156 for text
in childNode.childNodes:
158 dict[
"title"] = title
159 elif childNode.tagName ==
"keyword":
161 for text
in childNode.childNodes:
163 keywords = k.split(
",")
164 for i
in range(len(keywords)):
165 keywords[i] = str(keywords[i]).strip()
166 dict[
"key"] = keywords
167 if childNode.childNodes:
168 parseThroughDocumentInfo(childNode, dict)
170 parseThroughDocumentInfo(xmlroot.documentElement, dict)
171 keywords = dict[
"key"]
172 if "acbf_title" in keywords:
203 file = open(location,
"w", newline=
"", encoding=
"utf8")
205 file.write(
"msgid " + quote + quote + newLine)
206 file.write(
"msgstr " + quote + quote + newLine)
207 date = QDateTime.currentDateTimeUtc().toString(Qt.DateFormat.ISODate)
208 file.write(quote +
"POT-Creation-Date:" + date +
"\\n" + quote + newLine)
209 file.write(quote +
"Content-Type: text/plain; charset=UTF-8\\n" + quote + newLine)
210 file.write(quote +
"Content-Transfer-Encoding: 8bit\\n" + quote + newLine)
211 file.write(quote +
"X-Generator: Krita Comics Project Manager Tools Plugin\\n" + quote + newLine)
214 file.write(
"#. Title of the work" + newLine)
215 file.write(
"msgctxt \"@meta-title\"" + newLine)
216 file.write(
"msgid " + quote + metaData.get(
"title",
"") + quote + newLine)
217 file.write(
"msgstr " + quote + quote + newLine)
220 file.write(
"#. The summary" + newLine)
221 file.write(
"msgctxt \"@meta-summary\"" + newLine)
222 file.write(
"msgid " + quote + metaData.get(
"summary",
"") + quote + newLine)
223 file.write(
"msgstr " + quote + quote + newLine)
226 file.write(
"#. The keywords, these need to be comma separated." + newLine)
227 file.write(
"msgctxt \"@meta-keywords\"" + newLine)
228 file.write(
"msgid " + quote + metaData.get(
"keywords",
"") + quote + newLine)
229 file.write(
"msgstr " + quote + quote + newLine)
232 file.write(
"#. The header that will prepend translator's notes" + newLine)
233 file.write(
"msgctxt \"@meta-translator\"" + newLine)
234 file.write(
"msgid " + quote + metaData.get(
"transnotes",
"") + quote + newLine)
235 file.write(
"msgstr " + quote + quote + newLine)
240 file.write(
"msgctxt " + quote +
"@page-title" + quote + newLine)
241 file.write(
"msgid " + quote + title + quote + newLine)
242 file.write(
"msgstr " + quote + quote + newLine)
252 uniqueContext =
False
255 string = string.replace(quote,
"\\\"")
256 string = string.replace(
"\'",
"\\\'")
257 string = string.replace(
"#",
"\\#")
259 file.write(
"msgctxt " + quote + key + quote + newLine)
260 file.write(
"msgid " + quote + string + quote + newLine)
261 file.write(
"msgstr " + quote + quote + newLine)
263 print(
"CPMT: Translations have been written to:", location)