How do I declare a string with both single and double quotes in YAML?

前端 未结 3 1352
北海茫月
北海茫月 2020-12-10 10:39

I\'m internationalizing an application and cannot figure out how to declare a translation string that contains both single and double quotes. Here\'s an example of the en.ym

相关标签:
3条回答
  • 2020-12-10 10:47

    escaping should be done like this

    "When you're using double quotes, they look like \"this\""
    
    0 讨论(0)
  • 2020-12-10 10:53

    See if this works for you, it works perfectly for me in my spring boot applications where I needed to pass JSON values in:

    Using YAML pipe style:

    app.json:
      values: |
        {"key": "value"}
    

    Your case would be:

    en:
      my_string: |
        When you're using double quotes, they look like "this"
    

    Folded style might work too but I haven't tried.

    See more here: http://symfony.com/doc/current/components/yaml/yaml_format.html#strings

    0 讨论(0)
  • 2020-12-10 11:07

    Actually I can’t figure out why do you need obsolete typewriter quotes in translation strings. There is 2013 around and we are not stuck to ASCII-7 anymore. The typography rules dictate their demands to use unicode quotation marks.

    That’s the best practice ever: map those within 3rd keyboard level (or, eventually, sed your yml):

    "When you’re using double quotes, they look like “this”"
    

    With such an approach you’ll never run into troubles with escaping and your clients will definitely say “oh, neat.”

    Sorry, if this seems a little bit off-topic, but since the question was about translation strings, I still consider it to be the best solution.

    0 讨论(0)
提交回复
热议问题