简体   繁体   中英

use of YAML blocks in rails i18n locale files

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"

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM