Code

Ticket #1660: django_bidi.diff

File django_bidi.diff, 3.1 KB (added by meir@…, 8 years ago)
Line 
1Index: django/conf/global_settings.py
2===================================================================
3--- django/conf/global_settings.py      (revision 2714)
4+++ django/conf/global_settings.py      (working copy)
5@@ -62,6 +62,9 @@
6     ('zh-tw', _('Traditional Chinese')),
7 )
8 
9+# Languages using BiDi (right-to-left) layout
10+LANGUAGES_BIDI = ("he",)
11+
12 # Not-necessarily-technical managers of the site. They get broken link
13 # notifications and other various e-mails.
14 MANAGERS = ADMINS
15Index: django/templatetags/i18n.py
16===================================================================
17--- django/templatetags/i18n.py (revision 2714)
18+++ django/templatetags/i18n.py (working copy)
19@@ -23,6 +23,14 @@
20         context[self.variable] = translation.get_language()
21         return ''
22 
23+class GetCurrentLanguageBidiNode(Node):
24+    def __init__(self, variable):
25+        self.variable = variable
26+
27+    def render(self, context):
28+        context[self.variable] = translation.get_language_bidi()
29+        return ''
30+       
31 class TranslateNode(Node):
32     def __init__(self, value, noop):
33         self.value = value
34@@ -102,9 +110,26 @@
35     """
36     args = token.contents.split()
37     if len(args) != 3 or args[1] != 'as':
38-        raise TemplateSyntaxError, "'get_available_languages' requires 'as variable' (got %r)" % args
39+        raise TemplateSyntaxError, "'get_current_language' requires 'as variable' (got %r)" % args
40     return GetCurrentLanguageNode(args[2])
41 
42+def do_get_current_language_bidi(parser, token):
43+    """
44+    This will store the current language layout in the context.
45+
46+    Usage::
47+
48+        {% get_current_language_bidi as bidi %}
49+
50+    This will fetch the currently active language's layout and
51+    put it's value into the ``bidi`` context variable.
52+    True indicates right-to-left layout, otherwise left-to-right
53+    """
54+    args = token.contents.split()
55+    if len(args) != 3 or args[1] != 'as':
56+        raise TemplateSyntaxError, "'get_current_language_bidi' requires 'as variable' (got %r)" % args
57+    return GetCurrentLanguageBidiNode(args[2])
58+
59 def do_translate(parser, token):
60     """
61     This will mark a string for translation and will
62@@ -217,5 +242,6 @@
63 
64 register.tag('get_available_languages', do_get_available_languages)
65 register.tag('get_current_language', do_get_current_language)
66+register.tag('get_current_language_bidi', do_get_current_language_bidi)
67 register.tag('trans', do_translate)
68 register.tag('blocktrans', do_block_translate)
69Index: django/utils/translation.py
70===================================================================
71--- django/utils/translation.py (revision 2714)
72+++ django/utils/translation.py (working copy)
73@@ -212,6 +212,16 @@
74     from django.conf import settings
75     return settings.LANGUAGE_CODE
76 
77+def get_language_bidi():
78+    """
79+    Returns selected language's BiDi layout.
80+    False = left-to-right layout
81+    True = right-to-left layout
82+    """
83+   
84+    from django.conf import settings
85+    return get_language() in settings.LANGUAGES_BIDI
86+   
87 def catalog():
88     """
89     This function returns the current active catalog for further processing.