I pulled the patch from the upstream pull request and created a d/patches/ entry for it. Please included in Debian to fix the web2py support. The test code can be skipped if you want to limit the size of the patch.
-- Happy hacking Petter Reinholdtsen
diff --git a/debian/patches/series b/debian/patches/series index 290858707..9fee92537 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -8,3 +8,4 @@ storage_bzr poterminology_defaultstopfile sphinx-intersphinx.patch af-pootle.patch +web2py-fixes.patch diff --git a/debian/patches/web2py-fixes.patch b/debian/patches/web2py-fixes.patch new file mode 100644 index 000000000..7e5a51547 --- /dev/null +++ b/debian/patches/web2py-fixes.patch @@ -0,0 +1,231 @@ +Description: Fix web2py support +Author: Vinyl Darkscratch +Origin: https://github.com/translate/translate/pull/3838 +Bug: https://github.com/translate/translate/issues/3254 +Bug-Debian: https://bugs.debian.org/916745 +Forwarded: not-needed +Reviewed-By: <name and email of someone who approved the patch> +Last-Update: 2018-12-18 + +diff --git a/translate/convert/po2web2py.py b/translate/convert/po2web2py.py +index 07d61b358..c31f57fde 100755 +--- a/translate/convert/po2web2py.py ++++ b/translate/convert/po2web2py.py +@@ -1,3 +1,4 @@ ++#!/usr/bin/env python + # -*- coding: utf-8 -*- + # + # Copyright 2009-2010 Zuza Software Foundation +@@ -24,7 +25,9 @@ See: http://docs.translatehouse.org/projects/translate-toolkit/en/latest/command + for examples and usage instructions. + """ + +-from io import BytesIO ++import sys ++ ++from io import StringIO + + from translate.convert import convert + from translate.storage import factory +@@ -36,7 +39,7 @@ class po2pydict(object): + return + + def convertstore(self, inputstore, includefuzzy): +- str_obj = BytesIO() ++ str_obj = StringIO() + + mydict = dict() + for unit in inputstore.units: +@@ -49,29 +52,40 @@ class po2pydict(object): + # The older convention is to prefix with "*** ": + #mydict[unit.source] = '*** ' + unit.source + +- str_obj.write('{\n') +- for source_str in mydict: +- str_obj.write("%s:%s,\n" % (repr(str(source_str)), repr(str(mydict[source_str])))) +- str_obj.write('}\n') ++ str_obj.write(u'# -*- coding: utf-8 -*-\n') ++ str_obj.write(u'{\n') ++ for source_str, trans_str in sorted(mydict.items()): ++ if sys.version_info[0] == 2: ++ source_str = source_str.encode('utf-8') ++ trans_str = trans_str.encode('utf-8') ++ str_obj.write(u"%s: %s,\n" % (repr(source_str), repr(trans_str))) ++ str_obj.write(u'}\n') + str_obj.seek(0) + return str_obj + + + def convertpy(inputfile, outputfile, templatefile=None, includefuzzy=False, +- outputthreshold=None): ++ outputthreshold=None, **kwargs): + inputstore = factory.getobject(inputfile) + + if not convert.should_output_store(inputstore, outputthreshold): +- return False ++ return 0 + + convertor = po2pydict() + outputstring = convertor.convertstore(inputstore, includefuzzy) +- outputfile.write(outputstring.read()) ++ ++ if sys.version_info[0] == 2: ++ outputfile.write(outputstring.read()) ++ elif sys.version_info[0] > 2: ++ outputfile.write(bytes(outputstring.read(), 'utf-8')) + return 1 + + + def main(argv=None): +- formats = {("po", "py"): ("py", convertpy), ("po"): ("py", convertpy)} ++ formats = { ++ ("po", "py"): ("py", convertpy), ++ ("po", None): ("py", convertpy) ++ } + parser = convert.ConvertOptionParser(formats, usetemplates=False, description=__doc__) + parser.add_threshold_option() + parser.add_fuzzy_option() +diff --git a/translate/convert/test_po2web2py.py b/translate/convert/test_po2web2py.py +new file mode 100644 +index 000000000..7906a1230 +--- /dev/null ++++ b/translate/convert/test_po2web2py.py +@@ -0,0 +1,55 @@ ++# -*- coding: utf-8 -*- ++import sys ++ ++from translate.convert import po2web2py ++from translate.misc import wStringIO ++from translate.storage import po ++ ++ ++class TestPO2WEB2PY(object): ++ ++ def po2web2py(self, po_source): ++ """helper that converts po source to web2py source without requiring files""" ++ input_file = wStringIO.StringIO(po_source) ++ input_po = po.pofile(input_file) ++ convertor = po2web2py.po2pydict() ++ output_web2py = convertor.convertstore(input_po, False) ++ return output_web2py.read() ++ ++ def test_basic(self): ++ """test a basic po to web2py conversion""" ++ input_po = '''#: .text ++msgid "A simple string" ++msgstr "Du texte simple" ++''' ++ expected_web2py = '''# -*- coding: utf-8 -*- ++{ ++'A simple string': 'Du texte simple', ++} ++''' ++ web2py_out = self.po2web2py(input_po) ++ assert web2py_out == expected_web2py ++ ++ def test_ordering_serialize(self): ++ input_po = ''' ++#: .foo ++msgid "foo" ++msgstr "oof" ++ ++#: .bar ++msgid "bar" ++msgstr "rab" ++ ++#: .baz ++msgid "baz" ++msgstr "zab" ++''' ++ expected_web2py = '''# -*- coding: utf-8 -*- ++{ ++'bar': 'rab', ++'baz': 'zab', ++'foo': 'oof', ++} ++''' ++ web2py_out = self.po2web2py(input_po) ++ assert web2py_out == expected_web2py +diff --git a/translate/convert/test_web2py2po.py b/translate/convert/test_web2py2po.py +new file mode 100644 +index 000000000..60765fef1 +--- /dev/null ++++ b/translate/convert/test_web2py2po.py +@@ -0,0 +1,35 @@ ++# -*- coding: utf-8 -*- ++import sys ++ ++from translate.convert import web2py2po ++from translate.storage import po ++from translate.storage.test_base import first_translatable, headerless_len ++ ++ ++class TestWEB2PY2PO(object): ++ ++ def web2py2po(self, web2py_source): ++ """helper that converts po source to web2py source without requiring files""" ++ input_web2py = eval(web2py_source) ++ new_pofile = po.pofile() ++ convertor = web2py2po.web2py2po(new_pofile) ++ output_po = convertor.convertstore(input_web2py) ++ return output_po ++ ++ def singleelement(self, storage): ++ """checks that the pofile contains a single non-header element, and returns it""" ++ assert headerless_len(storage.units) == 1 ++ return first_translatable(storage) ++ ++ def test_basic(self): ++ """test a basic web2py to po conversion""" ++ input_web2py = '''# -*- coding: utf-8 -*- ++{ ++'A simple string': 'Du texte simple', ++} ++''' ++ ++ po_out = self.web2py2po(input_web2py) ++ pounit = self.singleelement(po_out) ++ assert pounit.source == "A simple string" ++ assert pounit.target == "Du texte simple" +diff --git a/translate/convert/web2py2po.py b/translate/convert/web2py2po.py +index 5ac777fa0..bb911050c 100755 +--- a/translate/convert/web2py2po.py ++++ b/translate/convert/web2py2po.py +@@ -1,3 +1,4 @@ ++#!/usr/bin/env python + # -*- coding: utf-8 -*- + # + # Copyright 2009-2010 Zuza Software Foundation +@@ -25,6 +26,7 @@ for examples and usage instructions. + """ + + from translate.storage import po ++import sys + + + class web2py2po(object): +@@ -40,12 +42,14 @@ class web2py2po(object): + return pounit + + def convertstore(self, mydict): +- + targetheader = self.mypofile.header() + targetheader.addnote("extracted from web2py", "developer") + + for source_str in mydict.keys(): + target_str = mydict[source_str] ++ if sys.version_info[0] == 2: ++ target_str = target_str.decode('utf-8') ++ source_str = source_str.decode('utf-8') + if target_str == source_str: + # a convention with new (untranslated) web2py files + target_str = u'' +@@ -58,7 +62,7 @@ class web2py2po(object): + return self.mypofile + + +-def convertpy(inputfile, outputfile, encoding="UTF-8"): ++def convertpy(inputfile, outputfile, encoding="UTF-8", **kwargs): + + new_pofile = po.pofile() + convertor = web2py2po(new_pofile)