简体   繁体   English

Rails 3中的多行I18n

[英]Multiline I18n in Rails 3

this is a simple question but i cannot really find the answer somewhere. 这是一个简单的问题,但我无法在某处找到答案。 How do you handle multiline translations in i18n in Rails ? 你如何在Rails中处理i18n中的多行翻译?

What i currently have is something like : 我现在拥有的是:

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

This works, i suppose because it's translated into html where spaces do not really matter if not in a pre tag. 这是有效的,我想因为它被翻译成html,如果不在预标签中,空格并不重要。 I feel this is not the correct way, though. 不过,我觉得这不是正确的方法。 And if so, what is really the correct way to do that ? 如果是这样,那么真正的正确方法是什么?

This really isnt an I18n question as probably a yaml question. 这真的不是一个I18n问题,可能是一个yaml问题。 Have you tried: 你有没有尝试过:

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

I placed the above in test.yml and in irb: 我将上面的内容放在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"

For your specific example try: 对于您的具体示例,尝试:

error:
  code: |
    Some really
    long error
    message here

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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