Shalafister's
Shalafister's

Reputation: 889

Rails internationalization if check not working

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

Answers (2)

dp7
dp7

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

Fallenhero
Fallenhero

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

Related Questions