aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2019-01-10 16:08:41 -0500
committerGitHub <noreply@github.com>2019-01-10 16:08:41 -0500
commitfd21b590d1e4e8dfd79748235f49d03dbe0e7eba (patch)
treeb100a7ee64d563a02059761747c6ca2584e9aaf0 /guides
parentebda02d017e623ce0edade5a5ed37ebf2f2c7442 (diff)
parent569a889291de428aab069a2af6bcfda8f37cff5d (diff)
downloadrails-fd21b590d1e4e8dfd79748235f49d03dbe0e7eba.tar.gz
rails-fd21b590d1e4e8dfd79748235f49d03dbe0e7eba.tar.bz2
rails-fd21b590d1e4e8dfd79748235f49d03dbe0e7eba.zip
Merge pull request #34911 from duleorlovic/guides_i18n
Add reasoning for `I18n.with_locale`
Diffstat (limited to 'guides')
-rw-r--r--guides/source/i18n.md6
1 files changed, 4 insertions, 2 deletions
diff --git a/guides/source/i18n.md b/guides/source/i18n.md
index 08cad375ef..d146685675 100644
--- a/guides/source/i18n.md
+++ b/guides/source/i18n.md
@@ -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