Changeset 1412
- Timestamp:
- 11/24/05 19:03:58 (3 years ago)
- Files:
-
- django/trunk/django/templatetags/i18n.py (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/templatetags/i18n.py
r1241 r1412 1 "Default tags used by the template system, available to all templates."2 3 1 from django.core.template import Node, NodeList, Template, Context, resolve_variable, resolve_variable_with_filters, registered_filters 4 2 from django.core.template import TemplateSyntaxError, register_tag, TokenParser 5 3 from django.core.template import TOKEN_BLOCK, TOKEN_TEXT, TOKEN_VAR 6 4 from django.utils import translation 7 8 import sys 9 import re 5 import re, sys 10 6 11 7 class GetAvailableLanguagesNode(Node): 12 13 8 def __init__(self, variable): 14 9 self.variable = variable … … 20 15 21 16 class GetCurrentLanguageNode(Node): 22 23 17 def __init__(self, variable): 24 18 self.variable = variable … … 29 23 30 24 class TranslateNode(Node): 31 32 25 def __init__(self, value, noop): 33 26 self.value = value … … 42 35 43 36 class BlockTranslateNode(Node): 44 45 37 def __init__(self, extra_context, singular, plural=None, countervar=None, counter=None): 46 38 self.extra_context = extra_context … … 79 71 in the context. 80 72 81 Usage is as follows::73 Usage:: 82 74 83 75 {% get_available_languages as languages %} … … 90 82 put it into the named variable. 91 83 """ 92 93 84 args = token.contents.split() 94 85 if len(args) != 3 or args[1] != 'as': … … 98 89 def do_get_current_language(parser, token): 99 90 """ 100 This will store the current language in 101 the context. 102 103 Usage is as follows:: 91 This will store the current language in the context. 92 93 Usage:: 104 94 105 95 {% get_current_language as language %} … … 109 99 variable. 110 100 """ 111 112 101 args = token.contents.split() 113 102 if len(args) != 3 or args[1] != 'as': … … 120 109 translate the string for the current language. 121 110 122 Usage is like this::111 Usage:: 123 112 124 113 {% trans "this is a test" %} … … 145 134 in there is something that is in the .po file. 146 135 """ 147 148 136 class TranslateParser(TokenParser): 149 150 137 def top(self): 151 138 value = self.value() … … 158 145 noop = False 159 146 return (value, noop) 160 161 147 (value, noop) = TranslateParser(token.contents).top() 162 148 return TranslateNode(value, noop) … … 166 152 This will translate a block of text with parameters. 167 153 168 Format is like this::154 Usage:: 169 155 170 156 {% blocktrans with foo|filter as bar and baz|filter as boo %} … … 172 158 {% endblocktrans %} 173 159 174 Additionally this supports pluralization::160 Additionally, this supports pluralization:: 175 161 176 162 {% blocktrans count var|length as count %} … … 232 218 register_tag('trans', do_translate) 233 219 register_tag('blocktrans', do_block_translate) 234
