Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Must return string or None #1

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions translationstring/__init__.py
Expand Up @@ -176,6 +176,9 @@ def translate(msgid, domain=None, mapping=None, context=None,
# spray these indignant comments all over this module. ;-) # spray these indignant comments all over this module. ;-)


if not isinstance(msgid, basestring): if not isinstance(msgid, basestring):
if msgid is not None:
msgid = str(msgid)

return msgid return msgid


tstring = msgid tstring = msgid
Expand Down
5 changes: 5 additions & 0 deletions translationstring/tests/test__init__.py
Expand Up @@ -119,6 +119,11 @@ def test_msgid_nonstring(self):
result = translate(None) result = translate(None)
self.assertEqual(result, 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): def test_chameleon_default_marker_returned(self):
# Chameleon uses a special StringMarker class as default value so it # Chameleon uses a special StringMarker class as default value so it
# can detect missing translations. # can detect missing translations.
Expand Down