[Libreoffice-commits] .: l10ntools/scripts
Miklos Vajna
vmiklos at kemper.freedesktop.org
Mon Oct 3 14:27:01 PDT 2011
l10ntools/scripts/po2lo | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
New commits:
commit d92a87f19534105ee9c29ba5e509fd99c31c3611
Author: Miklos Vajna <vmiklos at frugalware.org>
Date: Mon Oct 3 23:16:59 2011 +0200
fdo#41380: fix po2lo to support python3 as well
diff --git a/l10ntools/scripts/po2lo b/l10ntools/scripts/po2lo
index 0f81ebc..969f3ea 100755
--- a/l10ntools/scripts/po2lo
+++ b/l10ntools/scripts/po2lo
@@ -78,7 +78,7 @@ class Template:
"""Represents a reference template in SDF format."""
def __init__(self, path):
- sock = open(path)
+ sock = xopen(path, "r", encoding='utf-8')
self.lines = []
for line in sock:
entry = Entry(line.split('\t'))
@@ -88,7 +88,7 @@ class Template:
def translate(self, translations):
"""Translates entires in the template based on translations."""
- sock = open(options.output, "w")
+ sock = xopen(options.output, "w", encoding='utf-8')
for line in self.lines:
line.translate(translations)
sock.write("\t".join(line.items)+"\r\n")
@@ -103,7 +103,7 @@ class Translations:
for root, dirs, files in os.walk(options.input):
for file in files:
path = "%s/%s" % (root, file)
- sock = open(path)
+ sock = xopen(path, "r", encoding='utf-8')
buf = []
multiline = False
fuzzy = False
@@ -166,6 +166,13 @@ class Translations:
text = text.replace(tag, escaped_tag)
return text
+def xopen(path, mode, encoding):
+ """Wrapper around open() to support both python2 and python3."""
+ if sys.version_info >= (3,):
+ return open(path, mode, encoding=encoding)
+ else:
+ return open(path, mode)
+
def main():
"""Main function of this script."""
@@ -193,7 +200,7 @@ options = Options()
# used by sdf2po()
normalfilenamechars = "/#.0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
normalizetable = ""
-for i in map(chr, range(256)):
+for i in map(chr, list(range(256))):
if i in normalfilenamechars:
normalizetable += i
else:
More information about the Libreoffice-commits
mailing list