如何在rails上的.yml本地化文件中打破行?

我有一个带有一些本地化的terms.en.yml文件,例如:

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' 

我怎么能在那里打破一条线或创建一个段落?

这里有一些信息,但它对我没有帮助,我做错了。 http://yaml.org/spec/1.1/#b-paragraph-separator

这对我有用:

 en: hello: "Hello world" bye: | Bye! See you! error: > Something happend. Try later. 

用法:

 irb(main):001:0> I18n.t 'bye' => "Bye!\nSee you!\n" irb(main):002:0> I18n.t 'error' => "Something happend. Try later.\n" 

我认为你的答案意味着:

“如何使用断行和make rails输出(HTML)在.yml(YAML)文件中编写短语/段落包含那些断行?”

因此,对我来说,目标是在.yml(YAML)文件中使用分隔线编写一个短语,以便轻松理解最终输出,然后在我们的HTML中生成由Rails生成的确切输出。

为此,我们需要在.yml文件和.html.erb | .slim文件中采取一些简单的预防措施。

这是我怎么做的。

welcome_page.html.slim

 h4.white = t('welcome_html') 

请注意_html最后一部分。 如果您的翻译键以_html结尾,则您可以免费转义。 资料来源: http : //guides.rubyonrails.org/i18n.html#using-safe-html-translations

en.yml

 en: welcome_html: | Welcome on StackOverflow! This is your personal dashboard! 

所以现在我们的.yml文件中我们可以使用将被转义的HTML标记。 为了便于阅读和理解,我们希望如何使用“|”输出 yaml选项让我们在.yml文件中也有断行。 但提醒一下“|” 这里的选项只适合我们,对开发人员来说更具人性化和友好性。 “|” YAML选项不会影响输出! 我们也可以使用其他类似的YAML选项:

 en: welcome_html: > Welcome on StackOverflow! This is your personal dashboard! 

要么:

 en: welcome_html: Welcome on StackOverflow! This is your personal dashboard! 

要么:

 en: welcome_html: "Welcome on StackOverflow!This is your personal dashboard!" 

它们都产生相同的输出,因此现在您的HTML页面将反映该断开线。

如果要在代码中包含换行符,而不是在输出中:

 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的回答是使用_html作为YAML前缀大多数都有效,但是当它没有(例如在闪光警报中)时,您也可以尝试在模板中的本地化字符串上使用.html_safe

举个例子:

 <% flash.each do |name, msg| -%> <%= content_tag :div, msg.html_safe, class: name %> <% end -%>