Permalink
Browse files

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

This fixes #1
  • Loading branch information...
malthe authored and wichert committed Mar 3, 2011
1 parent 550121f commit 331dc75e4e3635dac6ebef1fd5249719f6ad4024
Showing with 9 additions and 1 deletion.
  1. +2 −1 CHANGES.txt
  2. +2 −0 translationstring/__init__.py
  3. +5 −0 translationstring/tests/test__init__.py
View
@@ -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)
@@ -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
@@ -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.

0 comments on commit 331dc75

Please sign in to comment.