Roo*_* V. 26 yaml localization ruby-on-rails
我有一个带有一些本地化的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'
Run Code Online (Sandbox Code Playgroud)
我怎么能在那里打破一条线或创建一个段落?
这里有一些信息,但它对我没有帮助,我做错了什么.http://yaml.org/spec/1.1/#b-paragraph-separator
jdo*_*doe 52
这对我有用:
en:
hello: "Hello world"
bye: |
Bye!
See you!
error: >
Something happend.
Try later.
Run Code Online (Sandbox Code Playgroud)
用法:
irb(main):001:0> I18n.t 'bye'
=> "Bye!\nSee you!\n"
irb(main):002:0> I18n.t 'error'
=> "Something happend. Try later.\n"
Run Code Online (Sandbox Code Playgroud)
Die*_*o D 12
我认为你的答案意味着:
"如何使用断行和make rails输出(HTML)在.yml(YAML)文件中编写短语/段落包含那些断行?"
因此,对我来说,目标是在.yml(YAML)文件中使用分隔线编写一个短语,以便轻松理解最终输出,然后在我们的HTML中生成由Rails生成的精确输出.
为此,我们需要在.yml文件和.html.erb | .slim文件中采取一些简单的预防措施.
这是我怎么做的.
welcome_page.html.slim
h4.white = t('welcome_html')
Run Code Online (Sandbox Code Playgroud)
请注意_html最后一部分.如果您的翻译密钥以_html结尾,则您可以免费转义.资料来源:http://guides.rubyonrails.org/i18n.html#using-safe-html-translations
en.yml
en:
welcome_html: |
Welcome on StackOverflow!</br>
This is your personal dashboard!
Run Code Online (Sandbox Code Playgroud)
所以现在在我们的.yml文件中,我们可以使用</ br>将被转义的HTML标记. 为了便于阅读和理解将如何出现我们想要使用的输出"|" yaml选项让我们在.yml文件中也有断行.但提醒一下"|" 这里的选项只适合我们,对开发人员来说更具人性化和友好性."|" YAML选项不会影响输出!我们也可以使用其他类似的YAML选项:
en:
welcome_html: >
Welcome on StackOverflow!</br>
This is your personal dashboard!
Run Code Online (Sandbox Code Playgroud)
要么:
en:
welcome_html:
Welcome on StackOverflow!</br>
This is your personal dashboard!
Run Code Online (Sandbox Code Playgroud)
要么:
en:
welcome_html: "Welcome on StackOverflow!</br>This is your personal dashboard!"
Run Code Online (Sandbox Code Playgroud)
它们都产生相同的输出,所以现在你的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
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
17631 次 |
最近记录: |