I have a terms.en.yml file with some localization, for example:
en:
devise:
registrations:
terms:
text: 'This agreement was written in English (US). To the extent any translated version of this agreement conflicts with the English version, the English version controls. Please note that Section 16 contains certain changes to the general terms for users outside the United States.\n\ Some new line'
How could i break a line or create a paragraph there?
Here`s some info but it did not helped to me,i had been doing something wrong. http://yaml.org/spec/1.1/#b-paragraph-separator
This works for me:
en:
hello: "Hello world"
bye: |
Bye!
See you!
error: >
Something happend.
Try later.
Usage:
irb(main):001:0> I18n.t 'bye'
=> "Bye!\nSee you!\n"
irb(main):002:0> I18n.t 'error'
=> "Something happend. Try later.\n"
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 breaklines, to easily understand the final output and then have that exact output in our HTML, generated by Rails.
For do that we need some easy precautions both on .yml file and in our .html.erb|.slim file.
This how I do it.
welcome_page.html.slim
h4.white = t('welcome_html')
Please here note the _html final part. If your translation key ends with _html, 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.
For read and understand easily how will appear the output we would like to use the "|" yaml option 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.
If you want to have linebreaks in the code, but not in the output:
en:
devise:
registrations:
terms:
text: >
This agreement was written in English (US).
To the extent any translated version of this
agreement conflicts with the English version,
the English version controls. Please note
that Section 16 contains certain changes to
the general terms for users outside the
United States.
Some new line
Diego D's answer with using _html
as YAML prefix mostly works, but when it doesn't (for example in a flash alert) you can also try using .html_safe
on your localised string in the template.
So as an example:
<% flash.each do |name, msg| -%>
<%= content_tag :div, msg.html_safe, class: name %>
<% end -%>