开发者

Multiline I18n in Rails 3

开发者 https://www.devze.com 2023-02-19 04:18 出处:网络
this is a simple question but i cannot really find the answer somewhere. How do you handle multiline translations in i18n in Rails ?

this is a simple question but i cannot really find the answer somewhere. How do you handle multiline translations in i18n in Rails ?

What i currently have is something like :

error:
  code:  "This is the first line of the text a开发者_如何学编程nd 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. 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. 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:

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
0

精彩评论

暂无评论...
验证码 换一张
取 消