summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Garcia <garcia.marc@gmail.com>2009-08-10 15:23:32 +0000
committerMarc Garcia <garcia.marc@gmail.com>2009-08-10 15:23:32 +0000
commitad9f56aad62d4f5e623fa5f553e84971832a39ee (patch)
tree5318b5aefff77db2a9c5553fb7156a0b1355f7c9
parentac70e26bafb47f8a69aa805273724fba29ccc26f (diff)
[soc2009/i18n] Refs #10891, fixed bug on blocktrans, that skipped translations of texts containing mac or dos end of lines.
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/i18n-improvements@11429 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/utils/translation/trans_real.py5
-rw-r--r--tests/regressiontests/i18n/tests.py14
2 files changed, 17 insertions, 2 deletions
diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py
index 27edc081c8..e9f0a36ab0 100644
--- a/django/utils/translation/trans_real.py
+++ b/django/utils/translation/trans_real.py
@@ -266,15 +266,16 @@ def do_translate(message, translation_function):
translation object to use. If no current translation is activated, the
message will be run through the default translation object.
"""
+ eol_message = message.replace('\r\n', '\n').replace('\r', '\n')
global _default, _active
t = _active.get(currentThread(), None)
if t is not None:
- result = getattr(t, translation_function)(message)
+ result = getattr(t, translation_function)(eol_message)
else:
if _default is None:
from django.conf import settings
_default = translation(settings.LANGUAGE_CODE)
- result = getattr(_default, translation_function)(message)
+ result = getattr(_default, translation_function)(eol_message)
if isinstance(message, SafeData):
return mark_safe(result)
return result
diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py
index eb19e7f4d3..693a3adacf 100644
--- a/tests/regressiontests/i18n/tests.py
+++ b/tests/regressiontests/i18n/tests.py
@@ -65,6 +65,20 @@ status.
>>> print s
Password
+Translations on files with mac or dos end of lines will be converted
+to unix eof in .po catalogs, and they have to match when retrieved
+
+>>> from django.utils.translation.trans_real import translation
+>>> ca_translation = translation('ca')
+>>> ca_translation._catalog[u'Mac\nEOF\n'] = u'Catalan Mac\nEOF\n'
+>>> ca_translation._catalog[u'Win\nEOF\n'] = u'Catalan Win\nEOF\n'
+>>> activate('ca')
+>>> ugettext(u'Mac\rEOF\r')
+u'Catalan Mac\nEOF\n'
+>>> ugettext(u'Win\r\nEOF\r\n')
+u'Catalan Win\nEOF\n'
+>>> deactivate()
+
Localization of dates and numbers
>>> import datetime