Ticket #1660: django_bidi.diff

File django_bidi.diff, 3.1 KB (added by meir@…, 19 years ago)
  • django/conf/global_settings.py

     
    6262    ('zh-tw', _('Traditional Chinese')),
    6363)
    6464
     65# Languages using BiDi (right-to-left) layout
     66LANGUAGES_BIDI = ("he",)
     67
    6568# Not-necessarily-technical managers of the site. They get broken link
    6669# notifications and other various e-mails.
    6770MANAGERS = ADMINS
  • django/templatetags/i18n.py

     
    2323        context[self.variable] = translation.get_language()
    2424        return ''
    2525
     26class 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       
    2634class TranslateNode(Node):
    2735    def __init__(self, value, noop):
    2836        self.value = value
     
    102110    """
    103111    args = token.contents.split()
    104112    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
    106114    return GetCurrentLanguageNode(args[2])
    107115
     116def 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
    108133def do_translate(parser, token):
    109134    """
    110135    This will mark a string for translation and will
     
    217242
    218243register.tag('get_available_languages', do_get_available_languages)
    219244register.tag('get_current_language', do_get_current_language)
     245register.tag('get_current_language_bidi', do_get_current_language_bidi)
    220246register.tag('trans', do_translate)
    221247register.tag('blocktrans', do_block_translate)
  • django/utils/translation.py

     
    212212    from django.conf import settings
    213213    return settings.LANGUAGE_CODE
    214214
     215def 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   
    215225def catalog():
    216226    """
    217227    This function returns the current active catalog for further processing.
Back to Top