Changes between Initial Version and Version 1 of Ticket #14808


Ignore:
Timestamp:
Nov 29, 2010, 3:32:17 PM (14 years ago)
Author:
Alex Gaynor
Comment:

Added formatting.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #14808 – Description

    initial v1  
    44fr-fr catalog) appears in a Template, they can switch to the french
    55locale to get an unescaped '.
    6 
     6{{{
    77In [1]: from django.template import Template, Context, mark_safe
    88In [2]: c = Context()
     
    1818In [8]: t.render(c)
    1919Out[8]: u"Aujourd'hui"
    20 
     20}}}
    2121I recommend this patch:
    22 
     22{{{
    2323Index: django/utils/translation/trans_real.py
    2424===================================================================
     
    4242    return result
    4343
    44 
     44}}}
    4545Result:
    46 
     46{{{
    4747In [1]: from django.template import Template, Context, mark_safe
    4848In [2]: c = Context()
     
    5555In [8]: t.render(c)
    5656Out[8]: u'Aujourd'hui'
    57 
     57}}}
    5858Additionally, the documentation should be updated to say that strings
    5959marked for translation in templates should not be marked as safe:
    60 
     60{{{
    6161{% trans "Today & Tomorrow"|safe|upper %} // Looks safe, but gets
    6262translated to French with a '.
    63 
     63}}}
    6464This is only actually safe if i18n is not used, which is why
    6565trans_null still has the ifinstance(SafeData) stuff.
     
    6868
    6969If USE_I18N is off:
    70 
     70{{{
    7171context.insert("today_and_tomo_var", mark_safe("Today & Tomorrow"))
    7272
    7373// Ok renders "Today & Tomorrow"
    74 
     74}}}
    7575If USE_I18N is on:
    76 
     76{{{
    7777context.insert("today_and_tomo_var", mark_safe("Today & Tomorrow"))
    7878
    7979// Not Ok. Renders "Today & Tomorrow" because the safe-ness is removed.
    80 
     80}}}
    8181To solve that django users would need to be advised *not* to
    8282pre-mark_safe translatable strings before putting them in the Context
     
    8484
    8585If USE_I18N is on:
    86 
     86{{{
    8787context.insert("today_and_tomo_var", "Today & Tomorrow")
    88 
    8988// Ok. Renders "Today & Tomorrow" because
    9089_render_value_in_context escapes the non-safe data.
     90}}}
    9191
    9292The many ways strings could be dealt with make this a tricky issue to solve.
Back to Top