Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R18n loads new locale only after first translation in Rails #87

Open
adie opened this issue Dec 23, 2012 · 2 comments
Open

R18n loads new locale only after first translation in Rails #87

adie opened this issue Dec 23, 2012 · 2 comments

Comments

@adie
Copy link

adie commented Dec 23, 2012

I've updated r18n gems from 1.1.0 to 1.1.3 and now when I'm changing locale the first translation on page is still in previous locale, but other translations are in current locale. After refreshing page everything is ok.
Also in development environent everything is working too thanks to reload_r18n filter, when I disable it I can reproduce the issue above.
I change locales using this action in controller (simplified):

def change_locale
  session[:locale] = params[:locale]
  redirect_to :back
end

In view if I write

<%= I18n.locale %>
<%= t('hello') %>
<%= I18n.locale %>

On first request without changing locale I'll get

en
Hello
en

When I'll try to change locale to :ru

en
Hello
ru

After just page refresh

ru
Привет
ru

As a workaround, I've added prepend_before_filter :set_locale:

def set_locale
  I18n.locale = session[:locale] if session[:locale]
end

And now it seems to be working fine.

@ai
Copy link
Member

ai commented Dec 23, 2012

Hm. It seems like compatibility issue between R18n and I18n.

But I can try to investigate it only after new year :(.

@AlexWayfer
Copy link
Collaborator

Can you please provide an example app with able to reproduce this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants