Skip to content

Commit 358120f

Browse files
committed
Let developer chose wether or not to translate LANGUAGES
1 parent f2637cf commit 358120f

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Current
1010
- Allow customizable Django.js initialization
1111
- Allow manual reload of context and URLs
1212
- Published Django.js on bower (thanks to Wasil Sergejczyk for the initial bower.json file)
13+
- Do not automatically translate languages name in context
1314

1415

1516
0.8.0 (2013-07-14)

djangojs/context_serializer.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from django.template.context import RequestContext
88
from django.utils import translation, six
9-
from django.utils.translation import ugettext_lazy as _
109

1110
from djangojs.conf import settings
1211
from djangojs.utils import LazyJsonEncoder
@@ -65,7 +64,7 @@ def as_json(self):
6564

6665
def process_LANGUAGES(self, languages, data):
6766
'''Serialize LANGUAGES as a localized dictionnary.'''
68-
return dict((code, _(name)) for code, name in languages)
67+
return dict(languages)
6968

7069
def process_LANGUAGE_CODE(self, language_code, data):
7170
'''

djangojs/tests/test_context.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from django.test import TestCase
1515
from django.test.client import RequestFactory
1616
from django.test.utils import override_settings
17+
from django.utils import six
1718
from django.utils import translation
1819
from django.utils import unittest
1920

@@ -130,16 +131,15 @@ def test_languages(self):
130131
for code, name in settings.LANGUAGES:
131132
self.assertEqual(languages[code], name)
132133

133-
@override_settings(LANGUAGE_CODE='en-us')
134-
def test_languages_localized(self):
135-
'''LANGUAGES should be localized'''
134+
@override_settings(LANGUAGE_CODE='en-us', LANGUAGES=[('fr', translation.ugettext_lazy('French'))])
135+
def test_ugettext_lazy(self):
136+
'''Serialization should not fail on lazy translations'''
136137
result = self.process_request(headers={'HTTP_ACCEPT_LANGUAGE': 'fr'})
137138
self.assertIn('LANGUAGES', result)
138139
languages = result['LANGUAGES']
139140
self.assertTrue(isinstance(languages, dict))
140-
translation.activate('fr')
141-
for code, name in settings.LANGUAGES:
142-
self.assertEqual(languages[code], translation.ugettext_lazy(name))
141+
self.assertTrue(isinstance(languages['fr'], six.text_type))
142+
self.assertEqual(languages['fr'], 'Français')
143143

144144
def test_any_custom_context_processor(self):
145145
'''Any custom context processor should be in context'''

0 commit comments

Comments
 (0)