mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
i18n guide: clarify interpolation rules in _html keys [ci skip]
This commit is contained in:
parent
4159159bec
commit
a8eb601831
1 changed files with 16 additions and 0 deletions
|
@ -676,6 +676,22 @@ en:
|
||||||
<div><%= t('title.html') %></div>
|
<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.
|
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)
|
![i18n demo html safe](images/i18n/demo_html_safe.png)
|
||||||
|
|
Loading…
Reference in a new issue