在 Rails i18n 语言环境文件中使用 YAML 块
因此,我希望能够将更长的文本块添加到 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自 http://pastie.org/1352791
config/locales/tx.yml
From http://pastie.org/1352791
config/locales/tx.yml