# This file is part of Beremiz
# Copyright (C) 2021: Edouard TISSERANT
# See COPYING file for copyrights details.
from __future__ import absolute_import
""" Opens PO file with POEdit """
if sys.platform.startswith('win'):
from six.moves import winreg
poedit_cmd = winreg.QueryValue(winreg.HKEY_LOCAL_MACHINE,
'SOFTWARE\\Classes\\poedit\\shell\\open\\command')
poedit_path = poedit_cmd.replace('"%1"', '').strip().replace('"', '')
poedit_path = subprocess.check_output("command -v poedit", shell=True).strip()
except subprocess.CalledProcessError:
wx.MessageBox("POEdit is not found or installed !")
subprocess.Popen([poedit_path,pofile])
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
"Project-Id-Version: PACKAGE VERSION\\n"
"POT-Creation-Date: %(time)s\\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n"
"Language-Team: LANGUAGE <LL@li.org>\\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: SVGHMI 1.0\\n"
def make_escapes(pass_iso8859):
escapes = [chr(i) for i in range(256)]
# Allow iso-8859 characters to pass through so that e.g. 'msgid
# "Höhe"' would result not result in 'msgid "H\366he"'. Otherwise we
# escape any character outside the 32..126 range.
escapes[i] = "\\%03o" % i
escapes[ord('\\')] = '\\\\'
escapes[ord('\t')] = '\\t'
escapes[ord('\r')] = '\\r'
escapes[ord('\n')] = '\\n'
escapes[ord('\"')] = '\\"'
make_escapes(pass_iso8859 = True)
s[i] = escapes[ord(s[i])]
return EMPTYSTRING.join(s)
# This converts the various Python string types into a format that is
# appropriate for .po files, namely much closer to C style.
s = '"' + escape(s) + '"'
lines[-1] = lines[-1] + '\n'
for i in range(len(lines)):
lines[i] = escape(lines[i])
s = '""\n"' + lineterm.join(lines) + '"'
def ImportMessages(self, msgs):
self.addentry("\n".join([line.text.encode("utf-8") for line in msg]), msg.get("label"), msg.get("id"))
def addentry(self, msg, label, svgid):
self.__messages.setdefault(msg, set()).add(entry)
timestamp = time.strftime('%Y-%m-%d %H:%M+%Z')
print >> fp, pot_header % {'time': timestamp}
for k, v in self.__messages.items():
reverse.setdefault(tuple(keys), []).append((k, v))
d = {'label': label, 'svgid': svgid}
s = _(' %(label)s:%(svgid)s') % d
if len(locline) + len(s) <= 78:
if len(locline) > len(locpfx):
print >> fp, 'msgid', normalize(k)
print >> fp, 'msgstr ""\n'
def add(msgid, msgstr, fuzzy):
"Add a non-fuzzy translation to the dictionary."
self.__messages[msgid] = msgstr
# If we get a comment line after a msgstr, this is a new entry
if l[0] == '#' and section == STR:
self.add(msgid, msgstr, fuzzy)
if l[:2] == '#,' and 'fuzzy' in l:
# Now we are in a msgid section, output previous section
if l.startswith('msgid') and not l.startswith('msgid_plural'):
self.add(msgid, msgstr, fuzzy)
# This is a message with plural forms
elif l.startswith('msgid_plural'):
print >> sys.stderr, 'msgid_plural not preceded by msgid on %s:%d' %\
msgid += '\0' # separator of singular and plural
# Now we are in a msgstr section
elif l.startswith('msgstr'):
if l.startswith('msgstr['):
print >> sys.stderr, 'plural without msgid_plural on %s:%d' %\
msgstr += '\0' # Separator of the various plural forms
print >> sys.stderr, 'indexed msgstr required for plural on %s:%d' %\
print >> sys.stderr, 'Syntax error on %s:%d' % (infile, lno), \
self.add(msgid, msgstr, fuzzy)