equal
deleted
inserted
replaced
15 import ast |
15 import ast |
16 import wx |
16 import wx |
17 import re |
17 import re |
18 from email.parser import HeaderParser |
18 from email.parser import HeaderParser |
19 |
19 |
20 # to have it for python 2, had to install |
|
21 # https://pypi.org/project/pycountry/18.12.8/ |
|
22 # python2 -m pip install pycountry==18.12.8 --user |
|
23 import pycountry |
20 import pycountry |
24 from dialogs import MessageBoxOnce |
21 from dialogs import MessageBoxOnce |
25 from POULibrary import UserAddressedException |
22 from POULibrary import UserAddressedException |
26 |
23 |
27 cmd_parser = re.compile(r'(?:"([^"]+)"\s*|([^\s]+)\s*)?') |
24 cmd_parser = re.compile(r'(?:"([^"]+)"\s*|([^\s]+)\s*)?') |
183 "MIME-Version: 1.0\\n" |
180 "MIME-Version: 1.0\\n" |
184 "Content-Type: text/plain; charset=UTF-8\\n" |
181 "Content-Type: text/plain; charset=UTF-8\\n" |
185 "Content-Transfer-Encoding: 8bit\\n" |
182 "Content-Transfer-Encoding: 8bit\\n" |
186 "Generated-By: SVGHMI 1.0\\n" |
183 "Generated-By: SVGHMI 1.0\\n" |
187 |
184 |
|
185 |
188 ''' |
186 ''' |
189 escapes = [] |
187 escapes = [] |
190 |
188 |
191 def make_escapes(): |
189 def make_escapes(): |
192 global escapes |
190 global escapes |
200 escapes[ord('\"')] = b'\\"' |
198 escapes[ord('\"')] = b'\\"' |
201 |
199 |
202 make_escapes() |
200 make_escapes() |
203 |
201 |
204 def escape(s): |
202 def escape(s): |
205 l = [escapes[c] if c < 128 else bytes([c]) for c in s] |
203 return b''.join([escapes[c] if c < 128 else bytes([c]) for c in s]) |
206 return b''.join(l) |
|
207 #return bytes([escapes[c] if c < 128 else c for c in s]) |
|
208 |
204 |
209 def normalize(s): |
205 def normalize(s): |
210 # This converts the various Python string types into a format that is |
206 # This converts the various Python string types into a format that is |
211 # appropriate for .po files, namely much closer to C style. |
207 # appropriate for .po files, namely much closer to C style. |
212 lines = s.split(b'\n') |
208 lines = s.split(b'\n') |
255 d = {b'label': label, b'svgid': svgid} |
251 d = {b'label': label, b'svgid': svgid} |
256 s = b' %(label)s:%(svgid)s' % d |
252 s = b' %(label)s:%(svgid)s' % d |
257 if len(locline) + len(s) <= 78: |
253 if len(locline) + len(s) <= 78: |
258 locline = locline + s |
254 locline = locline + s |
259 else: |
255 else: |
260 fp.write(locline) |
256 fp.write(locline + b'\n') |
261 locline = locpfx + s |
257 locline = locpfx + s |
262 if len(locline) > len(locpfx): |
258 if len(locline) > len(locpfx): |
263 fp.write(locline) |
259 fp.write(locline + b'\n') |
264 fp.write(b'msgid '+normalize(k)) |
260 fp.write(b'msgid ' + normalize(k) + b'\n') |
265 fp.write(b'msgstr ""\n') |
261 fp.write(b'msgstr ""\n\n') |
266 |
262 |
267 |
263 |
268 class POReader: |
264 class POReader: |
269 def __init__(self): |
265 def __init__(self): |
270 self.__messages = {} |
266 self.__messages = {} |