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

发布于 2024-09-24 16:28:36 字数 1757 浏览 0 评论 0原文

因此,我希望能够将更长的文本块添加到 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"

So I'd like to be able to add a longer block of text to a YAML locale file in Rails.
However, the YAML parser gives syntax errors for blocks that appear to be fine! I've read through the Ruby YAML cookbook and it seems like these examples below should all work, but they don't.

config/locales/tx.yml

This one works fine:

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"

...but is ugly.

None of these work...

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"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吃兔兔 2024-10-01 16:28:36

来自 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"

From 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"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文