Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Must always return a string, or ``None``.

This fixes #1
  • Loading branch information...
commit 331dc75e4e3635dac6ebef1fd5249719f6ad4024 1 parent 550121f
@malthe malthe authored wichert committed
View
3  CHANGES.txt
@@ -4,10 +4,11 @@ translationstring
Next release
------------
+- coerce non-string values to a string during translation, except for None.
+
- Honour mapping information passed to the translator, combining it with
mapping data already part of the translation string.
-
- Support formatting of translation strings with %-operator.
0.4 (09-22-2011)
View
2  translationstring/__init__.py
@@ -195,6 +195,8 @@ def translate(msgid, domain=None, mapping=None, context=None,
# spray these indignant comments all over this module. ;-)
if not isinstance(msgid, string_types):
+ if msgid is not None:
+ msgid = text_type(msgid)
return msgid
tstring = msgid
View
5 translationstring/tests/test__init__.py
@@ -151,6 +151,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.
Please sign in to comment.
Something went wrong with that request. Please try again.