Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Must return string or ``None`` #1

wants to merge 1 commit into from

2 participants


As shown in the test, an example of another such object is True; we must coerce this to a string. It might be an error by the developer, but the translate contract is clear: strings or None.

@wichert wichert closed this pull request from a commit
@malthe malthe Must always return a string, or ``None``.
This fixes #1
@wichert wichert closed this in 331dc75
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 3, 2011
  1. @malthe
This page is out of date. Refresh to see the latest.
3  translationstring/
@@ -176,6 +176,9 @@ def translate(msgid, domain=None, mapping=None, context=None,
# spray these indignant comments all over this module. ;-)
if not isinstance(msgid, basestring):
+ if msgid is not None:
+ msgid = str(msgid)
return msgid
tstring = msgid
5 translationstring/tests/
@@ -119,6 +119,11 @@ def test_msgid_nonstring(self):
result = translate(None)
self.assertEqual(result, None)
+ def test_msgid_not_none_not_string(self):
+ translate = self._makeOne(None)
+ result = translate(True)
+ self.assertEqual(result, 'True')
def test_chameleon_default_marker_returned(self):
# Chameleon uses a special StringMarker class as default value so it
# can detect missing translations.
Something went wrong with that request. Please try again.