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.yml字符串的示例
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?
如果只有双引号,我会将它用单引号括起来,反之亦然。我如何处理双引号和单引号?
3 个解决方案
#1
35
escaping should be done like this
逃避应该这样做
"When you're using double quotes, they look like \"this\""
#2
10
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.
实际上我无法弄清楚为什么你需要在翻译字符串中使用过时的打字机报价。有2013年左右,我们不再坚持ASCII-7了。排版规则规定了他们使用unicode引号的要求。
That’s the best practice ever: map those within 3rd keyboard level (or, eventually, sed
your yml
):
这是有史以来最好的做法:映射第三个键盘级别(或最终,你的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.
对不起,如果这看起来有点偏离主题,但由于问题是关于翻译字符串,我仍然认为它是最好的解决方案。
#3
1
See if this works for you, it works perfectly for me in my spring boot applications where I needed to pass JSON values in:
看看这是否适合您,它在我的Spring启动应用程序中对我来说非常适合我需要传递JSON值:
Using YAML pipe style:
使用YAML管道样式:
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
在此处查看更多信息:http://symfony.com/doc/current/components/yaml/yaml_format.html#strings
#1
35
escaping should be done like this
逃避应该这样做
"When you're using double quotes, they look like \"this\""
#2
10
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.
实际上我无法弄清楚为什么你需要在翻译字符串中使用过时的打字机报价。有2013年左右,我们不再坚持ASCII-7了。排版规则规定了他们使用unicode引号的要求。
That’s the best practice ever: map those within 3rd keyboard level (or, eventually, sed
your yml
):
这是有史以来最好的做法:映射第三个键盘级别(或最终,你的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.
对不起,如果这看起来有点偏离主题,但由于问题是关于翻译字符串,我仍然认为它是最好的解决方案。
#3
1
See if this works for you, it works perfectly for me in my spring boot applications where I needed to pass JSON values in:
看看这是否适合您,它在我的Spring启动应用程序中对我来说非常适合我需要传递JSON值:
Using YAML pipe style:
使用YAML管道样式:
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
在此处查看更多信息:http://symfony.com/doc/current/components/yaml/yaml_format.html#strings