I consider that your answer means:
How to write a phrase/paragraph in .yml
(YAML) file with break lines
and make rails output (HTML) contain those break lines?
So for me the goal is to write a phrase inside .yml
(YAML) file with break lines to easily understand the final output and then have that exact output also in our HTML, generated by Rails.
For do that we need some easy precautions both on .yml
file and in our .html
or .erb
or .slim
file (based on what you use).
Below how I do it.
welcome_page.html.slim
h4 = t('welcome_html')
Here note the _html
suffix. If your translation key ends with _html
suffix, you get escaping for free.
Source: http://guides.rubyonrails.org/i18n.html#using-safe-html-translations
en.yml
en:
welcome_html: |
Welcome on StackOverflow!<br>
This is your personal dashboard!
So now inside our .yml
file we can use <br>
HTML tag that will be escaped.
To also easily read and understand how will appear the output we would like to use the |
yaml special character that let us have break lines also inside .yml
file. But remind that |
option here is just for us, to be more human readable and friendly to the developer. |
YAML option won't affect the output!
Also we can use other YAML options like these:
en:
welcome_html: >
Welcome on StackOverflow!<br>
This is your personal dashboard!
or:
en:
welcome_html:
Welcome on StackOverflow!<br>
This is your personal dashboard!
or:
en:
welcome_html: "Welcome on StackOverflow!<br>This is your personal dashboard!"
They all produce the same output, so now your HTML page will reflect that break line.