aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authorCarlos Ramirez III <carlos@cetrasoft.com>2015-02-03 21:03:41 -0500
committerCarlos Ramirez III <carlos@cetrasoft.com>2015-02-03 21:03:41 -0500
commite17260ca91d2e75a71279c47034ed1c2c14c1396 (patch)
tree659c07bc2571cc6f04f71c88a23e7c4ca68819f1 /guides
parent1c59ffca5c8e998aa5cfc0abb594981de23e64c8 (diff)
downloadrails-e17260ca91d2e75a71279c47034ed1c2c14c1396.tar.gz
rails-e17260ca91d2e75a71279c47034ed1c2c14c1396.tar.bz2
rails-e17260ca91d2e75a71279c47034ed1c2c14c1396.zip
Document lazy lookup behavior for controllers
Pull request #7082 added lazy lookup to controllers using the translate method, but the documentation still stated that it was available for views only. [ci skip]
Diffstat (limited to 'guides')
-rw-r--r--guides/source/i18n.md19
1 files changed, 19 insertions, 0 deletions
diff --git a/guides/source/i18n.md b/guides/source/i18n.md
index fbee267975..8f24c53edb 100644
--- a/guides/source/i18n.md
+++ b/guides/source/i18n.md
@@ -588,6 +588,25 @@ you can look up the `books.index.title` value **inside** `app/views/books/index.
NOTE: Automatic translation scoping by partial is only available from the `translate` view helper method.
+"Lazy" lookup can also be used in _controllers_:
+
+```yaml
+en:
+ books:
+ create:
+ success: Book created!
+```
+which is especially useful for setting flash messages:
+
+```ruby
+class BooksController < ApplicationController
+ def create
+ # ...
+ redirect_to books_url, notice: t('.success')
+ end
+end
+```
+
### Interpolation
In many cases you want to abstract your translations so that **variables can be interpolated into the translation**. For this reason the I18n API provides an interpolation feature.