2011-03-24 59 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