在rails i18n语言环境文件中使用YAML块

时间:2010-09-22 18:17:23

标签: ruby-on-rails ruby yaml

所以我希望能够在Rails中的YAML语言环境文件中添加更长的文本块。 但是,YAML解析器为看起来很好的块提供了语法错误!我已经阅读了Ruby YAML食谱,看起来下面的这些例子都可行,但它们没有。

配置/区域设置/ tx.yml

这个很好用:

tx:
  states:
    show:
      state_population: "2009 est. pop.: 24,782,302 (cit. <a href=\"http://quickfacts.census.gov/qfd/states/48000.html\">Census.gov</a>"
      state_pop_per_upper_chamber_member: "Each senator serves a four-year term and represents approx. 774,447 Texans"

......但很难看。

这些都不起作用......

tx:
  states:
    show:
      state_population: |
        2009 est. pop.: 24,782,302 (cit. <a href="http://quickfacts.census.gov/qfd/states/48000.html">Census.gov</a>
      state_pop_per_upper_chamber_member: "Each senator serves a four-year term and represents approx. 774,447 Texans"


tx:
  states:
    show:
      state_population: >
        2009 est. pop.: 24,782,302 (cit. <a href="http://quickfacts.census.gov/qfd/states/48000.html">Census.gov</a>
      state_pop_per_upper_chamber_member: "Each senator serves a four-year term and represents approx. 774,447 Texans"

tx:
  states:
    show:
      state_population: |
        "2009 est. pop.: 24,782,302 (cit. <a href=\"http://quickfacts.census.gov/qfd/states/48000.html\">Census.gov</a>"
      state_pop_per_upper_chamber_member: "Each senator serves a four-year term and represents approx. 774,447 Texans"

tx:
  states:
    show:
      state_population: |
        2009 est. pop.\: 24,782,302 (cit. <a href="http://quickfacts.census.gov/qfd/states/48000.html">Census.gov</a>
      state_pop_per_upper_chamber_member: "Each senator serves a four-year term and represents approx. 774,447 Texans"

1 个答案:

答案 0 :(得分:1)

来自http://pastie.org/1352791

配置/区域设置/ tx.yml

tx:
  states:
    show:
      state_population: >
        2009 est. pop.: 24,782,302
        (cit.
        <a href=\"http://quickfacts.census.gov/qfd/states/48000.html\">Census.gov</a>)
      state_pop_per_upper_chamber_member: "Each senator serves a four-year term and     represents approx. 774,447 Texans"