Skip to content

Commit

Permalink
Add reasoning for I18n.with_locale and explanation that the problem is
Browse files Browse the repository at this point in the history
about leak into subsequent requests.

[ci skip]
  • Loading branch information
duleorlovic committed Jan 10, 2019
1 parent ebda02d commit 569a889
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions guides/source/i18n.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,12 @@ Note that appending directly to `I18n.load_paths` instead of to the application'

### Managing the Locale across Requests

The default locale is used for all translations unless `I18n.locale` is explicitly set.

A localized application will likely need to provide support for multiple locales. To accomplish this, the locale should be set at the beginning of each request so that all strings are translated using the desired locale during the lifetime of that request.

The default locale is used for all translations unless `I18n.locale=` or `I18n.with_locale` is used.

`I18n.locale` can leak into subsequent requests served by the same thread/process if it is not consistently set in every controller. For example executing `I18n.locale = :es` in one POST requests will have effects for all later requests to controllers that don't set the locale, but only in that particular thread/process. For that reason, instead of `I18n.locale =` you can use `I18n.with_locale` which does not have this leak issue.

The locale can be set in an `around_action` in the `ApplicationController`:

```ruby
Expand Down

0 comments on commit 569a889

Please sign in to comment.