Rails 3中的多行I18n

时间:2011-03-24 05:13:47

标签: ruby-on-rails yaml

这是一个简单的问题,但我无法在某处找到答案。你如何在Rails中处理i18n中的多行翻译?

我目前拥有的是:

error:
  code:  "This is the first line of the text and at some point it becomes too big. 
          So now i continue here."

这是有效的,我想因为它被翻译成html,如果没有预标签,空格并不重要。不过,我觉得这不是正确的方法。如果是这样,那么这是真正的正确方法吗?

1 个答案:

答案 0 :(得分:71)

这真的不是一个I18n问题,可能是一个yaml问题。你试过了吗?

 body : |
   This is a multi-line string.
   "special" metacharacters may
   appear here. The extent of this string is
   indicated by indentation.

我把上面的内容放在test.yml和irb:

irb(main):012:0> x= YAML.load(IO.read('test.yml'))
=> {"body"=>"This is a multi-line string.\n\"special\" metacharacters may\nappear here. The extent of this string is\nindicated by indentation.\n"}
irb(main):013:0> x["body"]
=> "This is a multi-line string.\n\"special\" metacharacters may\nappear here. The extent of this string is\nindicated by indentation.\n"

对于您的具体示例,请尝试:

error:
  code: |
    Some really
    long error
    message here