J.Luca
J.Luca

Reputation: 208

<% if I18n.locale == 'es' %> doesn't work

In my head.html.erb I have this

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

But I see

Language: es
This is not Spanish

How is it possible?!

I try to use <% if I18n.locale = 'es' %>, but the message "This is Spanish" is showed also if the I18n.locale is de, en, etc.

Upvotes: 1

Views: 306

Answers (1)

user229044
user229044

Reputation: 239342

I18n.locale returns a symbol, not a string. You need to compare against :es, not 'es'.

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

Upvotes: 4

Related Questions