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?
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.
@Denilson, XML (and therefore XHTML) allows both single and 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.
escaping should be done like this
"When you're using double quotes, they look like \"this\""
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With