Skip to content

Commit

Permalink
Fix Python 3.2 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
wichert committed Nov 5, 2014
1 parent 0d8e744 commit 220db70
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -2,6 +2,7 @@ language: python
python:
- "2.6"
- "2.7"
- "3.2"
- "3.3"
- "3.4"
- pypy
Expand Down
1 change: 1 addition & 0 deletions changes.rst
Expand Up @@ -6,6 +6,7 @@ translationstring

- Fix Python 3-specific test failures.

- Restore compatibility with Python 3.2.

1.2 (2014-11-04)
----------------
Expand Down
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -24,6 +24,7 @@
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.2",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: Implementation :: CPython",
Expand Down
10 changes: 6 additions & 4 deletions translationstring/__init__.py
Expand Up @@ -9,6 +9,8 @@
_interp_regex = re.compile(r'(?<!\$)(\$(?:(%(n)s)|{(%(n)s)}))'
% ({'n': NAME_RE}))

CONTEXT_MASK = text_type('%s\x04%s')

class TranslationString(text_type):
"""
The constructor for a :term:`translation string`. A translation
Expand Down Expand Up @@ -236,7 +238,7 @@ def ugettext_policy(translations, tstring, domain, context):

if context:
# Workaround for http://bugs.python.org/issue2504?
msgid = u'%s\x04%s' % (context, tstring)
msgid = CONTEXT_MASK % (context, tstring)
else:
msgid = tstring

Expand All @@ -253,7 +255,7 @@ def dugettext_policy(translations, tstring, domain, context):
context = context or getattr(tstring, 'context', None)
if context:
# Workaround for http://bugs.python.org/issue2504?
msgid = u'%s\x04%s' % (context, tstring)
msgid = CONTEXT_MASK % (context, tstring)
else:
msgid = tstring

Expand Down Expand Up @@ -329,7 +331,7 @@ def ungettext_policy(translations, singular, plural, n, domain, context):

if context:
# Workaround for http://bugs.python.org/issue2504?
msgid = u'%s\x04%s' % (context, singular)
msgid = CONTEXT_MASK % (context, singular)
else:
msgid = singular

Expand All @@ -345,7 +347,7 @@ def dungettext_policy(translations, singular, plural, n, domain, context):
domain = domain or default_domain
if context:
# Workaround for http://bugs.python.org/issue2504?
msgid = u'%s\x04%s' % (context, singular)
msgid = CONTEXT_MASK % (context, singular)
else:
msgid = singular
if getattr(translations, 'dungettext', None) is not None:
Expand Down

0 comments on commit 220db70

Please sign in to comment.