如何/应该在YAML文件中声明冒号(标点符号)? [英] How could/should I state colon (punctuation) in a YAML file?

查看:174
本文介绍了如何/应该在YAML文件中声明冒号(标点符号)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Ruby on Rails 3.1.0,我想知道如何在YAML文件中正确声明冒号(标点).我试图通过在我的 config/locales/defaults/en.yml文件

I am using Ruby on Rails 3.1.0 and I would like to know how to correctly state colon (punctuation) in a YAML file. I tried to support that by adding the following code in my config/locales/defaults/en.yml file

en
  # ':' is the HTML code for ':'
  test_key_html: Test value:

在我使用的查看文件中

t('test_key_html')

但是它不起作用(在前端内容中显示纯" 测试值: 文本).

but it doesn't work (in the front end content is displayed the "plain" Test value: text).

有可能吗?如果可以,怎么办?

推荐答案

您应该可以将值加双引号:

You should be able to double quote the value:

test_key_html: "Test value:"

这避免了YAML中的冒号混淆,并使冒号进入HTML.

This avoids colon-confusion in the YAML and gets your colon into your HTML.

irb 中考虑此问题:

>> { 'en' => { 'test_key_html' => 'Test value:' } }.to_yaml
=> "--- \nen: \n  test_key_html: "Test value:"\n"

这篇关于如何/应该在YAML文件中声明冒号(标点符号)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆