【问题标题】:use of YAML blocks in rails i18n locale files在 rails i18n 语言环境文件中使用 YAML 块
【发布时间】:2011-04-15 21:39:31
【问题描述】:

所以我希望能够向 Rails 中的 YAML 语言环境文件添加更长的文本块。 但是,YAML 解析器会为看起来不错的块提供语法错误!我通读了 Ruby YAML 食谱,似乎下面的这些示例应该都可以工作,但它们没有。

config/locales/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"

【问题讨论】:

  • 你看到了什么错误信息?
  • state_pop_per_upper_chamber_member 行总是出现语法错误。不幸的是,Ruby YAML 解析器没有提供很多细节。

标签: ruby-on-rails ruby yaml


【解决方案1】:

来自http://pastie.org/1352791

config/locales/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"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-28
    • 2013-10-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多