Skip to content

Commit

Permalink
Merge pull request #11 from zopefoundation/py3_unicode
Browse files Browse the repository at this point in the history
Fix unicode issue
  • Loading branch information
mauritsvanrees committed Mar 5, 2018
2 parents 0b583d1 + d2e12b6 commit 5712e09
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
==================
Expand Down
5 changes: 5 additions & 0 deletions src/zope/tal/talgettext.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
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
Expand All @@ -64,6 +68,7 @@

NLSTR = '"\n"'


def usage(code, msg=''):
# Python 2.1 required
print(__doc__, file=sys.stderr)
Expand Down
18 changes: 18 additions & 0 deletions src/zope/tal/tests/test_talgettext.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,24 @@ def test_dynamic_msgids(self):
['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__)

0 comments on commit 5712e09

Please sign in to comment.