【问题标题】:<% if I18n.locale == 'es' %> doesn't work<% if I18n.locale == 'es' %> 不起作用
【发布时间】:2020-08-02 11:44:48
【问题描述】:

在我的 head.html.erb 我有这个

Language: <%= I18n.locale %>
<% if I18n.locale == 'es' %>This is Spanish
<% else % >This is NOT Spanish
<% end %>

但我明白

Language: es
This is not Spanish

这怎么可能?!

我尝试使用 ,但如果 I18n.locale 是 de、en 等,也会显示消息“This is Spanish”。

【问题讨论】:

    标签: ruby-on-rails rails-i18n


    【解决方案1】:

    I18n.locale 返回一个符号,而不是一个字符串。您需要与:es 进行比较,而不是'es'。

    .irb(main):001:0> I18n.locale
    => :en
    irb(main):002:0> I18n.locale == 'en'
    => false
    irb(main):003:0> I18n.locale == :en
    => true
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-02
      • 2012-07-16
      • 2018-12-26
      • 2021-04-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多