Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
  • Loading branch information...
commit ca197739d9e586e65af023791ebabf1ea6057cd1 1 parent d9c4af6
Georg Bauer authored
View
3  django/conf/global_settings.py
@@ -62,6 +62,9 @@
('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
View
28 django/templatetags/i18n.py
@@ -23,6 +23,14 @@ def render(self, context):
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 top(self):
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)
View
10 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.
Please sign in to comment.
Something went wrong with that request. Please try again.