Ability to localize brand name in templates

- Take the value from the configuration and run it throught the Django
  translate method and make it available in Context.

- Use a no-op translate method to translate the text 'FreedomBox'.
This commit is contained in:
Sunil Mohan Adapa 2016-01-24 00:19:03 +05:30
parent cda3863d1b
commit a48068f775
No known key found for this signature in database
GPG Key ID: 36C361440C9BC971
2 changed files with 9 additions and 1 deletions

View File

@ -19,6 +19,7 @@
Django context processors to provide common data to templates.
"""
from django.utils.translation import ugettext as _, ugettext_noop
import re
from plinth import cfg
@ -30,10 +31,15 @@ def common(request):
Any resources referenced in the return value are expected to have been
initialized or configured externally beforehand.
"""
# Allow a value in configuration file to be translated. Allow
# the brand name 'FreedomBox' itself to be translated.
ugettext_noop('FreedomBox')
slash_indices = [match.start() for match in re.finditer('/', request.path)]
active_menu_urls = [request.path[:index + 1] for index in slash_indices]
return {
'cfg': cfg,
'submenu': cfg.main_menu.active_item(request),
'active_menu_urls': active_menu_urls
'active_menu_urls': active_menu_urls,
'box_name': _(cfg.box_name)
}

View File

@ -42,6 +42,8 @@ class ContextProcessorsTestCase(TestCase):
self.assertIsNotNone(config)
self.assertEqual('FreedomBox', config.box_name)
self.assertEqual('FreedomBox', response['box_name'])
submenu = response['submenu']
self.assertIsNone(submenu)