diff options
Diffstat (limited to 'app/controllers/concerns')
| -rw-r--r-- | app/controllers/concerns/pinned_to_default_locale.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/app/controllers/concerns/pinned_to_default_locale.rb b/app/controllers/concerns/pinned_to_default_locale.rb new file mode 100644 index 00000000..6c7fb900 --- /dev/null +++ b/app/controllers/concerns/pinned_to_default_locale.rb | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | # Chrome locale and content locale are separate concerns, and in the | ||
| 2 | # admin they must not touch. Globalize.locale falls back to | ||
| 3 | # I18n.locale when unset, so without this pin a visit to /en/admin | ||
| 4 | # would silently switch every Page and MenuItem read to its English | ||
| 5 | # translation. | ||
| 6 | # | ||
| 7 | # Translation editors are the exception and select their locale from | ||
| 8 | # params, not from the chrome. They nest their own | ||
| 9 | # Globalize.with_locale inside this one, which wins. | ||
| 10 | module PinnedToDefaultLocale | ||
| 11 | extend ActiveSupport::Concern | ||
| 12 | |||
| 13 | included do | ||
| 14 | around_action :pin_to_default_locale | ||
| 15 | end | ||
| 16 | |||
| 17 | private | ||
| 18 | |||
| 19 | def pin_to_default_locale | ||
| 20 | Globalize.with_locale(I18n.default_locale) { yield } | ||
| 21 | end | ||
| 22 | end | ||
