diff options
Diffstat (limited to 'l10ntools/scripts/po2lo')
-rwxr-xr-x | l10ntools/scripts/po2lo | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/l10ntools/scripts/po2lo b/l10ntools/scripts/po2lo index cdf8892fc950..6303c63a6fa7 100755 --- a/l10ntools/scripts/po2lo +++ b/l10ntools/scripts/po2lo @@ -41,6 +41,7 @@ class Entry: """Represents a single line in an SDF file.""" def __init__(self, items): + self.has_po = None self.items = items # list of 15 fields path = self.items[1].split('\\') self.po = "%s/%s/%s.po" % (options.input.replace('\\', '/'), self.items[0], "/".join(path[:-1])) @@ -65,13 +66,22 @@ class Entry: """Translates text in the entry based on translations.""" self.items[9] = options.language + self.items[2] = "" + self.has_po = False for idx, key in self.keys: try: - self.items[idx] = translations.data[(self.po, key)] + self.items[8] = str(translations.snumber[(self.po, key)]) + self.has_po = True + (text, fuzzy) = translations.data[(self.po, key)] + if fuzzy: + self.items[2] += "1" + else: + self.items[2] += "0" + self.items[idx] = text self.items[14] = "2002-02-02 02:02:02" except KeyError: - pass + self.items[idx]="" self.items[14] = self.items[14].strip() def sdf2po(self, s): @@ -95,8 +105,11 @@ class Template: sock = xopen(options.output, "w", encoding='utf-8') for line in self.lines: + temp = "\t".join(line.items) line.translate(translations) - sock.write("\t".join(line.items)+"\r\n") + if line.has_po: + sock.write(temp) + sock.write("\t".join(line.items)+"\r\n") sock.close() class Translations: @@ -104,6 +117,8 @@ class Translations: def __init__(self): self.data = {} + self.snumber = {} + counter = 0 for root, dirs, files in os.walk(options.input): for file in files: path = "%s/%s" % (root, file) @@ -115,16 +130,17 @@ class Translations: for line in sock: if line.startswith("#: "): key = line.strip()[3:] + fuzzy = False elif line.startswith("#, fuzzy"): fuzzy = True + elif line.startswith("msgid "): + counter = counter + 1 + self.setserialnumber(path, key, counter) elif line.startswith("msgstr "): trans = line.strip()[8:-1] if len(trans): - if fuzzy: - fuzzy = False - else: - self.setdata(path, key, trans) - multiline = False + self.setdata(path, key, trans, fuzzy) + multiline = False else: buf = [] buf.append(trans) @@ -132,16 +148,13 @@ class Translations: elif multiline and line.startswith('"'): buf.append(line.strip()[1:-1]) elif multiline and not len(line.strip()) and len("".join(buf)): - if fuzzy: - fuzzy = False - else: - self.setdata(path, key, "".join(buf)) + self.setdata(path, key, "".join(buf),fuzzy) buf = [] multiline = False - if multiline and len("".join(buf)) and not fuzzy: - self.setdata(path, key, "".join(buf)) + if multiline and len("".join(buf)): + self.setdata(path, key, "".join(buf),fuzzy) - def setdata(self, path, key, s): + def setdata(self, path, key, s, fuzzy = False): """Sets the translation for a given path and key, handling (un)escaping as well.""" if key: @@ -151,7 +164,10 @@ class Translations: s = self.escape_help_text(s) else: s = s.replace('\\\\', '\\') - self.data[(path.replace('\\', '/'), key)] = s + self.data[(path.replace('\\', '/'), key)] = ( s , fuzzy ) + + def setserialnumber(self, path, key, number): + self.snumber[(path.replace('\\', '/'), key)] = ( number ) def escape_help_text(self, text): """Escapes the help text as it would be in an SDF file.""" |