Skip to content

Commit

Permalink
Thread-safe locale switching (#4237)
Browse files Browse the repository at this point in the history
  • Loading branch information
deivid-rodriguez authored and tramuntanal committed Oct 9, 2018
1 parent 392d40b commit cf2d73c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Decidim::User.where(**search for old subscribed users**).update(newsletter_notif
- **decidim-core**: Fix newsletter opt-in migration [\#4198](https://github.com/decidim/decidim/pull/4198)
- **decidim-core**: Hide weird flash message [\#4235](https://github.com/decidim/decidim/pull/4235)
- **decidim-core**: Fix newsletter subscription checkbox always being unchecked [\#4238](https://github.com/decidim/decidim/pull/4238)
- **decidim-core**: Thread safe locale switching [\#4237](https://github.com/decidim/decidim/pull/4237)

**Removed**:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ module LocaleSwitcher
extend ActiveSupport::Concern

included do
before_action :set_locale
around_action :switch_locale
helper_method :current_locale, :available_locales, :default_locale

# Sets the locale for the current session.
#
# Returns nothing.
def set_locale
def switch_locale(&action)
locale = if params["locale"]
params["locale"]
elsif current_user && current_user.locale.present?
current_user.locale
end

I18n.locale = available_locales.include?(locale) ? locale : default_locale
I18n.with_locale(available_locales.include?(locale) ? locale : default_locale, &action)
end

# Adds the current locale to all the URLs generated by url_for so users
Expand Down

0 comments on commit cf2d73c

Please sign in to comment.