From a48068f775e9d4f3842a205afc2614a1000fa368 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sun, 24 Jan 2016 00:19:03 +0530 Subject: [PATCH] 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'. --- plinth/context_processors.py | 8 +++++++- plinth/tests/test_context_processors.py | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/plinth/context_processors.py b/plinth/context_processors.py index 433e0dd4b..d7de023ee 100644 --- a/plinth/context_processors.py +++ b/plinth/context_processors.py @@ -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) } diff --git a/plinth/tests/test_context_processors.py b/plinth/tests/test_context_processors.py index bf627ff54..f92296b59 100644 --- a/plinth/tests/test_context_processors.py +++ b/plinth/tests/test_context_processors.py @@ -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)