Django

Code

Changeset 726

Show
Ignore:
Timestamp:
09/29/05 12:01:05 (3 years ago)
Author:
hugo
Message:

i18n patch - references #65

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/i18n/django/conf/admin_templates/index.html

    r684 r726  
    2424 
    2525            {% if model.perms.add %} 
    26                 <td class="x50"><a href="{{ model.admin_url }}add/" class="addlink">Add</a></td> 
     26                <td class="x50"><a href="{{ model.admin_url }}add/" class="addlink">{% i18n _('Add') %}</a></td> 
    2727            {% else %} 
    2828                <td class="x50">&nbsp;</td> 
     
    3030 
    3131            {% if model.perms.change %} 
    32                 <td class="x75"><a href="{{ model.admin_url }}" class="changelink">Change</a></td> 
     32                <td class="x75"><a href="{{ model.admin_url }}" class="changelink">{% i18n _('Change') %}</a></td> 
    3333            {% else %} 
    3434                <td class="x75">&nbsp;</td> 
     
    4848<div id="content-related"> 
    4949    <div class="module" id="recent-actions-module"> 
    50         <h2>Recent Actions</h2> 
    51         <h3>My Actions</h3> 
     50        <h2>{% i18n _('Recent Actions') %}</h2> 
     51        <h3>{% i18n _('My Actions') %}</h3> 
    5252            {% load auth.log %} 
    5353            {% get_admin_log 10 as admin_log for_user user %} 
    5454            {% if not admin_log %} 
    55             <p>None available</p> 
     55            <p>{% i18n _('None available') %}</p> 
    5656            {% else %} 
    5757            <ul class="actionlist"> 
  • django/branches/i18n/django/conf/settings.py

    r239 r726  
    5656        delattr(me, k) 
    5757del me, k 
     58 
     59# as the last step, install the translation machinery and 
     60# remove the module again to not clutter the namespace. 
     61from django.utils import translation 
     62translation.install() 
     63del translation 
     64 
  • django/branches/i18n/django/core/defaulttags.py

    r574 r726  
    11"Default tags used by the template system, available to all templates." 
    22 
     3import re 
    34import sys 
    45import template 
     6 
     7from django.utils import translation 
    58 
    69class CommentNode(template.Node): 
     
    284287        return str(int(round(ratio))) 
    285288 
     289class I18NNode(template.Node): 
     290 
     291    def __init__(self, cmd): 
     292        self.cmd = cmd 
     293        self.i18n_re = re.compile(r'^\s*_\((.*)\)\s*$') 
     294 
     295    def render(self, context): 
     296        m = self.i18n_re.match(self.cmd) 
     297        if m: 
     298            s = m.group(1) 
     299            if s.startswith("'") and s.endswith("'"): 
     300                s = s[1:-1] 
     301            elif s.startswith('"""') and s.endswith('"""'): 
     302                s = s[3:-3] 
     303            elif s.startswith('"') and s.endswith('"'): 
     304                s = s[1:-1] 
     305            else: 
     306                raise template.TemplateSyntaxError("i18n must be called as {% i18n _('some message') %}") 
     307            return translation.gettext(s) % context 
     308        else: 
     309            raise template.TemplateSyntaxError("i18n must be called as {% i18n _('some message') %}") 
     310 
    286311def do_comment(parser, token): 
    287312    """ 
     
    746771    return WidthRatioNode(this_value_var, max_value_var, max_width) 
    747772 
     773def do_i18n(parser, token): 
     774    """ 
     775    translate a given string with the current 
     776    translation object. 
     777 
     778    For example:: 
     779 
     780        {% i18n _('test') %} 
     781 
     782    """ 
     783    args = token.contents.split(' ', 1) 
     784    if len(args) != 2: 
     785        raise template.TemplateSyntaxError("'i18n' requires one argument (got %r)" % args) 
     786 
     787    return I18NNode(args[1].strip()) 
     788 
    748789template.register_tag('comment', do_comment) 
    749790template.register_tag('cycle', do_cycle) 
     
    762803template.register_tag('templatetag', do_templatetag) 
    763804template.register_tag('widthratio', do_widthratio) 
     805template.register_tag('i18n', do_i18n) 
     806 
  • django/branches/i18n/django/core/validators.py

    r712 r726  
    5454def isAlphaNumeric(field_data, all_data): 
    5555    if not alnum_re.search(field_data): 
    56         raise ValidationError, "This value must contain only letters, numbers and underscores." 
     56        raise ValidationError, _("This value must contain only letters, numbers and underscores.") 
    5757 
    5858def isAlphaNumericURL(field_data, all_data): 
  • django/branches/i18n/setup.py

    r662 r726  
    1818                        'admin_media/css/*.css', 'admin_media/img/admin/*.gif', 
    1919                        'admin_media/img/admin/*.png', 'admin_media/js/*.js', 
    20                         'admin_media/js/admin/*js'], 
     20                        'admin_media/js/admin/*js', 'locale/*/*/*.mo'], 
    2121    }, 
    2222    scripts = ['django/bin/django-admin.py'],