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
This commit is contained in:
Georg Bauer 2006-05-16 07:35:20 +00:00
parent d9c4af6b37
commit ca197739d9
3 changed files with 40 additions and 1 deletions

View File

@ -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

View File

@ -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)

View File

@ -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.