diff options
author | Maurits van Rees <maurits@vanrees.org> | 2018-03-05 14:28:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-05 14:28:06 +0100 |
commit | 5712e0936dac5a300d85619f0a9fafd01ab7d231 (patch) | |
tree | b5ed031e4533a6f748b139db466a216dd38787bf | |
parent | 0b583d1e851c549a9d8a91e8fad2fbace8d72887 (diff) | |
parent | d2e12b6b54c7a204dc2954b71f5a6ee3efba80f1 (diff) | |
download | zope-tal-5712e0936dac5a300d85619f0a9fafd01ab7d231.tar.gz |
Merge pull request #11 from zopefoundation/py3_unicode
Fix unicode issue
-rw-r--r-- | CHANGES.rst | 2 | ||||
-rw-r--r-- | src/zope/tal/talgettext.py | 5 | ||||
-rw-r--r-- | src/zope/tal/tests/test_talgettext.py | 18 |
3 files changed, 25 insertions, 0 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index 3abe971..c437cd4 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -7,6 +7,8 @@ - Host documentation at https://zopetal.readthedocs.io +- Fix a ``NameError`` on Python 3 in talgettext.py affecting i18ndude. + See https://github.com/zopefoundation/zope.tal/pull/11 4.3.0 (2017-08-08) ================== diff --git a/src/zope/tal/talgettext.py b/src/zope/tal/talgettext.py index 4d8de80..a4e3917 100644 --- a/src/zope/tal/talgettext.py +++ b/src/zope/tal/talgettext.py @@ -44,6 +44,10 @@ from zope.tal.interfaces import ITALExpressionEngine from zope.tal.taldefs import TALExpressionError from zope.i18nmessageid import Message +PY3 = sys.version_info > (3,) +if PY3: + unicode = str + pot_header = '''\ # SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR ORGANIZATION @@ -64,6 +68,7 @@ msgstr "" NLSTR = '"\n"' + def usage(code, msg=''): # Python 2.1 required print(__doc__, file=sys.stderr) diff --git a/src/zope/tal/tests/test_talgettext.py b/src/zope/tal/tests/test_talgettext.py index d3b57d0..1e3b3f9 100644 --- a/src/zope/tal/tests/test_talgettext.py +++ b/src/zope/tal/tests/test_talgettext.py @@ -118,6 +118,24 @@ class test_POEngine(unittest.TestCase): ['A <a href="${DYNAMIC_CONTENT}">link</a>.', 'Some ${DYNAMIC_CONTENT} text.']) + def test_potalinterpreter_translate_default(self): + sample_source = '<p i18n:translate="">text</p>' + p = HTMLTALParser() + p.parseString(sample_source) + program, macros = p.getCode() + engine = POEngine() + engine.file = 'sample_source' + interpreter = POTALInterpreter( + program, macros, engine, stream=StringIO(), metal=False) + # We simply call this, to make sure we don't get a NameError + # for 'unicode' in python 3. + # The return value (strangely: 'x') is not interesting here. + interpreter.translate('text') + msgids = [] + for domain in engine.catalog.values(): + msgids += list(domain) + self.assertIn('text', msgids) + def test_suite(): return unittest.defaultTestLoader.loadTestsFromName(__name__) |