Rails 3中的多行I18n

Spy*_*ros 30 yaml ruby-on-rails

这是一个简单的问题,但我无法在某处找到答案.你如何在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."
Run Code Online (Sandbox Code Playgroud)

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

Jak*_*sey 71

这真的不是一个I18n问题,可能是一个yaml问题.你有没有尝试过:

 body : |
   This is a multi-line string.
   "special" metacharacters may
   appear here. The extent of this string is
   indicated by indentation.
Run Code Online (Sandbox Code Playgroud)

我将上面的内容放在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"
Run Code Online (Sandbox Code Playgroud)

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

error:
  code: |
    Some really
    long error
    message here
Run Code Online (Sandbox Code Playgroud)