Ruby on rails <;%如果I18n.locale==';es';%&燃气轮机;不';行不通

Ruby on rails <;%如果I18n.locale==';es';%&燃气轮机;不';行不通,ruby-on-rails,rails-i18n,Ruby On Rails,Rails I18n,在我的head.html.erb中我有这个 Language: <%= I18n.locale %> <% if I18n.locale == 'es' %>This is Spanish <% else % >This is NOT Spanish <% end %> 怎么可能 我尝试使用,但如果I18n.locale为de、en等,也会显示消息“This is Spanish”(这是西班牙语)。I18n.locale返回符号,而不是字符串。您

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

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


我尝试使用,但如果I18n.locale为de、en等,也会显示消息“This is Spanish”(这是西班牙语)。

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

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