【问题标题】:why is I18n.locale not a string为什么 I18n.locale 不是字符串
【发布时间】:2012-01-26 03:54:06
【问题描述】:

我正在访问 I18n.locale 变量以确定语言,并且我必须将其转换为字符串以始终进行比较。

I18n.locale.to_s

I18n.locale.to_s == "en" ? "h2-high-quality.gif" : "h2-high-quality-fr.gif"

我做错了什么还是必须这样做?

【问题讨论】:

    标签: ruby-on-rails-3 internationalization


    【解决方案1】:

    I18n.locale 是一个符号。您无需转换为字符串即可进行比较,只需与符号进行比较即可:

    I18n.locale == :en ? "h2-high-quality.gif" : "h2-high-quality-fr.gif"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-25
      • 1970-01-01
      • 2014-01-16
      • 1970-01-01
      • 2012-06-20
      • 1970-01-01
      • 1970-01-01
      • 2013-01-12
      相关资源
      最近更新 更多