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

Using around_action to set the locale #127

Closed
andyduong1920 opened this issue Oct 18, 2019 · 2 comments · Fixed by #241
Closed

Using around_action to set the locale #127

andyduong1920 opened this issue Oct 18, 2019 · 2 comments · Fixed by #241
Assignees

Comments

@andyduong1920
Copy link
Member

Why

To set the locale in before_action, there will is a case that the I18n can't get the default locale for some request, I faced that in a project.

For more details:

Solution

I think we should go with the Rails way, using around_action instead - https://guides.rubyonrails.org/i18n.html#managing-the-locale-across-requests

@malparty
Copy link
Member

@andyduong1920 do you have more information about this case? What was the problem? In which situation was the local not assigned properly? (maybe in an Engine controller that did not inherit from the main ::ApplicationController? 🤔 )

My case is that around_action is resetting the locale to the default value after the action, and this is bad with Devise flash messages when login fails: because devise redirects to the login page, and sets the flash message after the action is completed, so the locale value used will be the default one, not the current one =/

Thanks for your lights! 🙌

@andyduong1920
Copy link
Member Author

That is the case @malparty we set the locale on before_action, but the flash message didn't get localized.

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