Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
authored May 16, 2006
3  django/conf/global_settings.py
@@ -62,6 +62,9 @@
62 62
     ('zh-tw', _('Traditional Chinese')),
63 63
 )
64 64
 
  65
+# Languages using BiDi (right-to-left) layout
  66
+LANGUAGES_BIDI = ("he",)
  67
+
65 68
 # Not-necessarily-technical managers of the site. They get broken link
66 69
 # notifications and other various e-mails.
67 70
 MANAGERS = ADMINS
28  django/templatetags/i18n.py
@@ -23,6 +23,14 @@ def render(self, context):
23 23
         context[self.variable] = translation.get_language()
24 24
         return ''
25 25
 
  26
+class GetCurrentLanguageBidiNode(Node):
  27
+    def __init__(self, variable):
  28
+        self.variable = variable
  29
+
  30
+    def render(self, context):
  31
+        context[self.variable] = translation.get_language_bidi()
  32
+        return ''
  33
+        
26 34
 class TranslateNode(Node):
27 35
     def __init__(self, value, noop):
28 36
         self.value = value
@@ -102,9 +110,26 @@ def do_get_current_language(parser, token):
102 110
     """
103 111
     args = token.contents.split()
104 112
     if len(args) != 3 or args[1] != 'as':
105  
-        raise TemplateSyntaxError, "'get_available_languages' requires 'as variable' (got %r)" % args
  113
+        raise TemplateSyntaxError, "'get_current_language' requires 'as variable' (got %r)" % args
106 114
     return GetCurrentLanguageNode(args[2])
107 115
 
  116
+def do_get_current_language_bidi(parser, token):
  117
+    """
  118
+    This will store the current language layout in the context.
  119
+
  120
+    Usage::
  121
+
  122
+        {% get_current_language_bidi as bidi %}
  123
+
  124
+    This will fetch the currently active language's layout and
  125
+    put it's value into the ``bidi`` context variable.
  126
+    True indicates right-to-left layout, otherwise left-to-right
  127
+    """
  128
+    args = token.contents.split()
  129
+    if len(args) != 3 or args[1] != 'as':
  130
+        raise TemplateSyntaxError, "'get_current_language_bidi' requires 'as variable' (got %r)" % args
  131
+    return GetCurrentLanguageBidiNode(args[2])
  132
+
108 133
 def do_translate(parser, token):
109 134
     """
110 135
     This will mark a string for translation and will
@@ -217,5 +242,6 @@ def top(self):
217 242
 
218 243
 register.tag('get_available_languages', do_get_available_languages)
219 244
 register.tag('get_current_language', do_get_current_language)
  245
+register.tag('get_current_language_bidi', do_get_current_language_bidi)
220 246
 register.tag('trans', do_translate)
221 247
 register.tag('blocktrans', do_block_translate)
10  django/utils/translation.py
@@ -212,6 +212,16 @@ def get_language():
212 212
     from django.conf import settings
213 213
     return settings.LANGUAGE_CODE
214 214
 
  215
+def get_language_bidi():
  216
+    """
  217
+    Returns selected language's BiDi layout.
  218
+    False = left-to-right layout
  219
+    True = right-to-left layout
  220
+    """
  221
+    
  222
+    from django.conf import settings
  223
+    return get_language() in settings.LANGUAGES_BIDI
  224
+    
215 225
 def catalog():
216 226
     """
217 227
     This function returns the current active catalog for further processing.

0 notes on commit ca19773

Please sign in to comment.
Something went wrong with that request. Please try again.