mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
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:
parent
cda3863d1b
commit
a48068f775
@ -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)
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user