From ca197739d9e586e65af023791ebabf1ea6057cd1 Mon Sep 17 00:00:00 2001 From: Georg Bauer Date: Tue, 16 May 2006 07:35:20 +0000 Subject: [PATCH] fixed #1660: added support functions and tags for bidi language support git-svn-id: http://code.djangoproject.com/svn/django/trunk@2911 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/conf/global_settings.py | 3 +++ django/templatetags/i18n.py | 28 +++++++++++++++++++++++++++- django/utils/translation.py | 10 ++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py index cfa174287b..a61b9a30dc 100644 --- a/django/conf/global_settings.py +++ b/django/conf/global_settings.py @@ -62,6 +62,9 @@ LANGUAGES = ( ('zh-tw', _('Traditional Chinese')), ) +# Languages using BiDi (right-to-left) layout +LANGUAGES_BIDI = ("he",) + # Not-necessarily-technical managers of the site. They get broken link # notifications and other various e-mails. MANAGERS = ADMINS diff --git a/django/templatetags/i18n.py b/django/templatetags/i18n.py index 0c601535af..37b8d93908 100644 --- a/django/templatetags/i18n.py +++ b/django/templatetags/i18n.py @@ -23,6 +23,14 @@ class GetCurrentLanguageNode(Node): context[self.variable] = translation.get_language() return '' +class GetCurrentLanguageBidiNode(Node): + def __init__(self, variable): + self.variable = variable + + def render(self, context): + context[self.variable] = translation.get_language_bidi() + return '' + class TranslateNode(Node): def __init__(self, value, noop): self.value = value @@ -102,9 +110,26 @@ def do_get_current_language(parser, token): """ args = token.contents.split() if len(args) != 3 or args[1] != 'as': - raise TemplateSyntaxError, "'get_available_languages' requires 'as variable' (got %r)" % args + raise TemplateSyntaxError, "'get_current_language' requires 'as variable' (got %r)" % args return GetCurrentLanguageNode(args[2]) +def do_get_current_language_bidi(parser, token): + """ + This will store the current language layout in the context. + + Usage:: + + {% get_current_language_bidi as bidi %} + + This will fetch the currently active language's layout and + put it's value into the ``bidi`` context variable. + True indicates right-to-left layout, otherwise left-to-right + """ + args = token.contents.split() + if len(args) != 3 or args[1] != 'as': + raise TemplateSyntaxError, "'get_current_language_bidi' requires 'as variable' (got %r)" % args + return GetCurrentLanguageBidiNode(args[2]) + def do_translate(parser, token): """ This will mark a string for translation and will @@ -217,5 +242,6 @@ def do_block_translate(parser, token): register.tag('get_available_languages', do_get_available_languages) register.tag('get_current_language', do_get_current_language) +register.tag('get_current_language_bidi', do_get_current_language_bidi) register.tag('trans', do_translate) register.tag('blocktrans', do_block_translate) diff --git a/django/utils/translation.py b/django/utils/translation.py index a877f60009..0ee09e5b94 100644 --- a/django/utils/translation.py +++ b/django/utils/translation.py @@ -212,6 +212,16 @@ def get_language(): from django.conf import settings return settings.LANGUAGE_CODE +def get_language_bidi(): + """ + Returns selected language's BiDi layout. + False = left-to-right layout + True = right-to-left layout + """ + + from django.conf import settings + return get_language() in settings.LANGUAGES_BIDI + def catalog(): """ This function returns the current active catalog for further processing.