Reputation: 889
I have a rails app and working with two languages.
Interestingly, when I check the following in main.html.erb
;
MYLOCAL <%= I18n.locale == "en" %>|<%= I18n.locale %>
outputs;
false|en
Why would that happen ?
Upvotes: 0
Views: 42
Reputation: 6749
I18n.locale
#return :en which is a symbol
I18n.locale == :en #return true
Note: Comparing Symbol
would be a better practice than converting it to a String
and comparing it.
Upvotes: 1
Reputation: 1583
Because I18n.locale
returns a symbol. In your case :en
.
And <%= I18n.locale %>
calls to_s
For correct result try:
<%= I18n.locale.to_s == "en" %>|<%= I18n.locale %>
or
<%= I18n.locale == :en %>|<%= I18n.locale %>
Upvotes: 2