2011-03-24 98 views
30

这是一个简单的问题,但我找不到答案的地方。你如何在Rails中处理i18n中的多行翻译?Multiline I18n in Rails 3

我目前拥有的是一样的东西:

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

这工作,我想是因为它转换为HTML,其中的空间并不真的如果不是在一个预先标记关系。不过,我觉得这不是正确的做法。如果是这样,那么真正做到这一点的正确方法是什么?

回答

68

这真的不是一个国际化的问题,可能是一个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 
+0

添加关键字YAML – Spyros 2011-03-24 05:31:01

+1

你能否详细说明一点点 ?这个想法是什么?你把一个|然后你的字符串使用相同的缩进?我无法真正把它工作。 – Spyros 2011-03-24 05:33:05

+0

更新了我的答案..是的,您使用|在键之后开始多行文本缩进并保持长字符串的缩进。 – 2011-03-24 05:50:41