Skip to content
This repository
Browse code

update guides, use html safe translations in i18n

  • Loading branch information...
commit bcbc484b13d7fc0bed002a1cea5f5591053a8953 1 parent 4e37995
Alexey Vakhov avakhov authored vijaydev committed
BIN  railties/guides/assets/images/i18n/demo_html_safe.png
22 railties/guides/source/i18n.textile
Source Rendered
@@ -448,6 +448,7 @@ Covered are features like these:
448 448 * looking up translations
449 449 * interpolating data into translations
450 450 * pluralizing translations
  451 +* using safe HTML translations
451 452 * localizing dates, numbers, currency, etc.
452 453
453 454 h4. Looking up Translations
@@ -599,6 +600,27 @@ The +I18n.locale+ defaults to +I18n.default_locale+ which defaults to :+en+. The
599 600 I18n.default_locale = :de
600 601 </ruby>
601 602
  603 +h4. Using Safe HTML Translations
  604 +
  605 +Keys with a '_html' suffix and keys named 'html' are marked as HTML safe. Use them in views without escaping.
  606 +
  607 +<ruby>
  608 +# config/locales/en.yml
  609 +en:
  610 + welcome: <b>welcome!</b>
  611 + hello_html: <b>hello!</b>
  612 + title:
  613 + html: <b>title!</b>
  614 +
  615 +# app/views/home/index.html.erb
  616 +<div><%= t('welcome') %></div>
  617 +<div><%= raw t('welcome') %></div>
  618 +<div><%= t('hello_html') %></div>
  619 +<div><%= t('title.html') %></div>
  620 +</ruby>
  621 +
  622 +!images/i18n/demo_html_safe.png(i18n demo html safe)!
  623 +
602 624 h3. How to Store your Custom Translations
603 625
604 626 The Simple backend shipped with Active Support allows you to store translations in both plain Ruby and YAML format. [2]

0 comments on commit bcbc484

Please sign in to comment.
Something went wrong with that request. Please try again.