【问题标题】:How could/should I state colon (punctuation) in a YAML file?我如何/应该在 YAML 文件中声明冒号(标点符号)?
【发布时间】:2012-02-05 17:01:43
【问题描述】:

我正在使用 Ruby on Rails 3.1.0,我想知道如何在 YAML 文件中正确声明冒号(标点符号)。我试图通过在我的config/locales/defaults/en.yml file 中添加以下代码来支持这一点

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

在我使用的视图文件中

t('test_key_html')

但它不起作用(在前端内容中显示“纯”Test value: 文本)。

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

【问题讨论】:

    标签: html ruby-on-rails ruby ruby-on-rails-3 yaml


    【解决方案1】:

    你应该可以双引号:

    test_key_html: "Test value:"
    

    这可以避免 YAML 中的冒号混淆,并将冒号放入 HTML。

    irb 中考虑这一点:

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

    【讨论】:

      【解决方案2】:

      试试

      raw(t('test_key_html'))
      

      Rails 3+ 自动转义 html 标记

      【讨论】:

        猜你喜欢
        • 2014-01-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-11-28
        • 2013-02-06
        • 1970-01-01
        • 2013-01-30
        相关资源
        最近更新 更多