aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2014-09-10 19:23:41 +0200
committerXavier Noria <fxn@hashref.com>2014-09-10 19:25:31 +0200
commita8eb6018318f65e34486da8d1860b3f0d774383d (patch)
tree7081a223d50b7e996f27f00baaa3912e5b85534c
parent4159159bece42c328726b7d95fb17925392f83e9 (diff)
downloadrails-a8eb6018318f65e34486da8d1860b3f0d774383d.tar.gz
rails-a8eb6018318f65e34486da8d1860b3f0d774383d.tar.bz2
rails-a8eb6018318f65e34486da8d1860b3f0d774383d.zip
i18n guide: clarify interpolation rules in _html keys [ci skip]
-rw-r--r--guides/source/i18n.md16
1 files changed, 16 insertions, 0 deletions
diff --git a/guides/source/i18n.md b/guides/source/i18n.md
index 1023598aa4..0761d5b39c 100644
--- a/guides/source/i18n.md
+++ b/guides/source/i18n.md
@@ -676,6 +676,22 @@ en:
<div><%= t('title.html') %></div>
```
+Interpolation escapes as needed though. For example, given:
+
+```yaml
+en:
+ welcome_html: "<b>Welcome %{username}!</b>"
+```
+
+you can safely pass the username as set by the user:
+
+```erb
+<%# This is safe, it is going to be escaped if needed. %>
+<%= t('welcome_html', username: @current_user.username %>
+```
+
+Safe strings on the other hand are interpolated verbatim.
+
NOTE: Automatic conversion to HTML safe translate text is only available from the `translate` view helper method.
![i18n demo html safe](images/i18n/demo_html_safe.png)