I'm trying to determine whether to show the Spanish
or English
button on my web application.
<% if I18n.locale == 'es' %>
<a href="<%= set_english_path %>" class="thin">English</a>
<% else %>
<a href="<%= set_spanish_path %>" class="thin">Spanish</a>
<% end %>
The if
condition always fails and the Spanish button is always displayed.
RubyMine show this upon inspection (during debugging):
So why is the comparison failing?
You should use symbol instead of string when searching/comparing/setting locale. Try:
<% if I18n.locale == :es %>
Documentation for I18n is there http://guides.rubyonrails.org/i18n.html
In my case
if I18n.locale.to_s == 'zh-CN'
...
did the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With