How could/should I state colon (punctuation) in a YAML file?

旧城冷巷雨未停 提交于 2020-01-14 06:55:10

问题


I am using Ruby on Rails 3.1.0 and I would like to know how to correctly state colon (punctuation) in a YAML file. I tried to support that by adding the following code in my config/locales/defaults/en.yml file

en
  # ':' is the HTML code for ':'
  test_key_html: Test value:

and in my view file I used

t('test_key_html')

but it doesn't work (in the front end content is displayed the "plain" Test value: text).

Is it possible? If so how?


回答1:


You should be able to double quote the value:

test_key_html: "Test value:"

This avoids colon-confusion in the YAML and gets your colon into your HTML.

Consider this in irb:

>> { 'en' => { 'test_key_html' => 'Test value:' } }.to_yaml
=> "--- \nen: \n  test_key_html: "Test value:"\n"



回答2:


Try

raw(t('test_key_html'))

Rails 3+ automattically escapes html markup



来源:https://stackoverflow.com/questions/8783705/how-could-should-i-state-colon-punctuation-in-a-yaml-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!