Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.yml string that I am trying to

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

With the above string, I get the following error:

can not load translations from /vagrant/config/locales/en.yml, expected it to return a hash, but does not 

If there were just double quotes, I would wrap it in single quotes and vise-versa. How do I handle both double and single quotes though?

like image 723
Peter Brown Avatar asked Feb 21 '13 00:02

Peter Brown


People also ask

Can you use double quotes in YAML?

When quotes are used in YAML files, it is better to use double than single. Because double escape syntax matches industry conventions (backslash), while single surprisingly does not. So single quoting can lead to downstream problems when the author is not being exceptionally careful.

Which is a valid string that contains both single quotes and double quotes?

@Denilson, XML (and therefore XHTML) allows both single and double quotes.

How do you pass a string with double quotes?

If you need to use the double quote inside the string, you can use the backslash character. Notice how the backslash in the second line is used to escape the double quote characters. And the single quote can be used without a backslash.


1 Answers

escaping should be done like this

"When you're using double quotes, they look like \"this\"" 
like image 178
jvnill Avatar answered Sep 24 '22 10:09

jvnill