Permalink
Browse files

refactor the translation of the URLs + tests

  • Loading branch information...
1 parent 53990d1 commit e5406093fd66edc980660edc521e0f0f1f17c72c @Fantomas42 committed Mar 12, 2013
Showing with 29 additions and 6 deletions.
  1. +3 −1 zinnia/tests/__init__.py
  2. +20 −0 zinnia/tests/translated_urls.py
  3. +6 −5 zinnia/urls/__init__.py
View
4 zinnia/tests/__init__.py
@@ -31,6 +31,7 @@
from zinnia.tests.admin_filters import AuthorListFilterTestCase
from zinnia.tests.admin_filters import CategoryListFilterTestCase
from zinnia.tests.flags import FlagsTestCase
+from zinnia.tests.translated_urls import TranslatedURLsTestCase
from zinnia.signals import disconnect_entry_signals
from zinnia.signals import disconnect_discussion_signals
@@ -52,7 +53,8 @@ def suite():
EntryAdminTestCase, CategoryAdminTestCase,
MixinTestCase, LongEnoughTestCase,
AuthorTestCase, FlagsTestCase,
- AuthorListFilterTestCase, CategoryListFilterTestCase)
+ AuthorListFilterTestCase, CategoryListFilterTestCase,
+ TranslatedURLsTestCase)
if 'django_xmlrpc' in settings.INSTALLED_APPS:
test_cases += (PingBackTestCase, MetaWeblogTestCase)
View
20 zinnia/tests/translated_urls.py
@@ -0,0 +1,20 @@
+"""Test cases for Zinnia's translated URLs"""
+from django.test import TestCase
+from django.utils.translation import activate
+from django.utils.translation import deactivate
+
+from zinnia.urls import i18n_url
+
+
+class TranslatedURLsTestCase(TestCase):
+ """Test cases for translated URLs"""
+
+ def test_translated_urls(self):
+ deactivate()
+ self.assertEquals(
+ i18n_url(r'^authors/'), r'^authors/')
+ activate('fr')
+ self.assertEquals(
+ i18n_url(r'^authors/', True), r'^auteurs/')
+ self.assertEquals(
+ i18n_url(r'^authors/', False), r'^authors/')
View
11 zinnia/urls/__init__.py
@@ -8,14 +8,15 @@
from zinnia.settings import TRANSLATED_URLS
-def _(url_to_translate):
+def i18n_url(url, translate=TRANSLATED_URLS):
"""
- Translate or not the default Zinnia's URLs.
+ Translate or not an URL part.
"""
- if TRANSLATED_URLS:
- return ugettext_lazy(url_to_translate)
- return url_to_translate
+ if translate:
+ return ugettext_lazy(url)
+ return url
+_ = i18n_url
urlpatterns = patterns(
'',

0 comments on commit e540609

Please sign in to comment.