ruby-on-rails - 在 rails i18n 语言环境文件中使用 YAML block

标签 ruby-on-rails ruby yaml

因此,我希望能够将更长的文本 block 添加到 Rails 中的 YAML 语言环境文件中。 但是,YAML 解析器会为看似正常的 block 提供语法错误!我通读了 Ruby YAML 说明书,似乎下面的这些示例都应该有效,但它们却没有。

配置/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"

最佳答案

来自 http://pastie.org/1352791

配置/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"

关于ruby-on-rails - 在 rails i18n 语言环境文件中使用 YAML block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3772385/

相关文章:

Ruby 的 String#hex 混淆

python - 使用 ruamel.yaml 安全转储和加载 defaultdict

javascript - jQuery toggle() 在 Rails 中不起作用

ruby-on-rails - 如何限制 Rack 中的请求大小?

ruby-on-rails - 如何在两个日期之间生成随机日期和时间?

哈希数组的 YAML 缩进

amazon-web-services - 使用 cloudformation 模板创建 ec2 实例的镜像

mysql - 使用 mongoid(通过 ActiveRecord)作为延迟作业的后端有什么好处?

javascript - 尝试将 ruby​​ 代码转换为 javascript 时出错

ruby-on-rails - 您如何为下一个项目选择合适的 Ruby gem?