Changes between Initial Version and Version 1 of Ticket #14808
- Timestamp:
- Nov 29, 2010, 3:32:17 PM (14 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #14808 – Description
initial v1 4 4 fr-fr catalog) appears in a Template, they can switch to the french 5 5 locale to get an unescaped '. 6 6 {{{ 7 7 In [1]: from django.template import Template, Context, mark_safe 8 8 In [2]: c = Context() … … 18 18 In [8]: t.render(c) 19 19 Out[8]: u"Aujourd'hui" 20 20 }}} 21 21 I recommend this patch: 22 22 {{{ 23 23 Index: django/utils/translation/trans_real.py 24 24 =================================================================== … … 42 42 return result 43 43 44 44 }}} 45 45 Result: 46 46 {{{ 47 47 In [1]: from django.template import Template, Context, mark_safe 48 48 In [2]: c = Context() … … 55 55 In [8]: t.render(c) 56 56 Out[8]: u'Aujourd'hui' 57 57 }}} 58 58 Additionally, the documentation should be updated to say that strings 59 59 marked for translation in templates should not be marked as safe: 60 60 {{{ 61 61 {% trans "Today & Tomorrow"|safe|upper %} // Looks safe, but gets 62 62 translated to French with a '. 63 63 }}} 64 64 This is only actually safe if i18n is not used, which is why 65 65 trans_null still has the ifinstance(SafeData) stuff. … … 68 68 69 69 If USE_I18N is off: 70 70 {{{ 71 71 context.insert("today_and_tomo_var", mark_safe("Today & Tomorrow")) 72 72 73 73 // Ok renders "Today & Tomorrow" 74 74 }}} 75 75 If USE_I18N is on: 76 76 {{{ 77 77 context.insert("today_and_tomo_var", mark_safe("Today & Tomorrow")) 78 78 79 79 // Not Ok. Renders "Today & Tomorrow" because the safe-ness is removed. 80 80 }}} 81 81 To solve that django users would need to be advised *not* to 82 82 pre-mark_safe translatable strings before putting them in the Context … … 84 84 85 85 If USE_I18N is on: 86 86 {{{ 87 87 context.insert("today_and_tomo_var", "Today & Tomorrow") 88 89 88 // Ok. Renders "Today & Tomorrow" because 90 89 _render_value_in_context escapes the non-safe data. 90 }}} 91 91 92 92 The many ways strings could be dealt with make this a tricky issue to solve.