Pet*_*own 32 ruby yaml ruby-on-rails
我正在国际化一个应用程序,无法弄清楚如何声明包含单引号和双引号的转换字符串.这是我正在尝试的en.yml字符串的示例
en:
my_string: When you're using double quotes, they look like "this"
Run Code Online (Sandbox Code Playgroud)
使用上面的字符串,我收到以下错误:
can not load translations from /vagrant/config/locales/en.yml,
expected it to return a hash, but does not
Run Code Online (Sandbox Code Playgroud)
如果只有双引号,我会用单引号括起来,反之亦然.我如何处理双引号和单引号?
jvn*_*ill 42
逃避应该这样做
"When you're using double quotes, they look like \"this\""
Run Code Online (Sandbox Code Playgroud)
Ale*_*kin 12
实际上我无法弄清楚为什么你需要在翻译字符串中使用过时的打字机报价.有2013年左右,我们不再坚持ASCII-7了.排版规则规定了他们使用unicode引号的要求.
这是有史以来最好的做法:映射第三个键盘级别(或最终,sed你的yml):
"When you’re using double quotes, they look like “this”"
Run Code Online (Sandbox Code Playgroud)
通过这种方法,您将永远不会遇到逃避的麻烦,您的客户肯定会说"哦,整洁."
对不起,如果这看起来有点偏离主题,但由于问题是关于翻译字符串,我仍然认为它是最好的解决方案.
看看这是否适合你,它在我需要传递 JSON 值的 Spring Boot 应用程序中非常适合我:
使用 YAML 管道样式:
app.json:
values: |
{"key": "value"}
Run Code Online (Sandbox Code Playgroud)
你的情况是:
en:
my_string: |
When you're using double quotes, they look like "this"
Run Code Online (Sandbox Code Playgroud)
折叠样式也可以,但我没试过。
在此处查看更多信息:http : //symfony.com/doc/current/components/yaml/yaml_format.html#strings
| 归档时间: |
|
| 查看次数: |
28839 次 |
| 最近记录: |