aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2017-01-31 00:04:17 -0500
committerGitHub <noreply@github.com>2017-01-31 00:04:17 -0500
commit1c79936023cfffdd21f2b5ef4321111ad97ef651 (patch)
tree50823c688b63900bf77a7f317edbc684865c6d12
parentce97c79445f9ac4b056e34deaaaaf25cadc08b72 (diff)
parentd4ddf7b72f52597d0c0f90794cf52f6d0d687d4e (diff)
downloadrails-1c79936023cfffdd21f2b5ef4321111ad97ef651.tar.gz
rails-1c79936023cfffdd21f2b5ef4321111ad97ef651.tar.bz2
rails-1c79936023cfffdd21f2b5ef4321111ad97ef651.zip
Merge pull request #27842 from richseviora/master
Added warning for reserved YAML keywords.
-rw-r--r--guides/source/i18n.md29
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/locales/en.yml10
2 files changed, 39 insertions, 0 deletions
diff --git a/guides/source/i18n.md b/guides/source/i18n.md
index 4db6e3e195..0b7cc055be 100644
--- a/guides/source/i18n.md
+++ b/guides/source/i18n.md
@@ -409,6 +409,35 @@ NOTE: You need to restart the server when you add new locale files.
You may use YAML (`.yml`) or plain Ruby (`.rb`) files for storing your translations in SimpleStore. YAML is the preferred option among Rails developers. However, it has one big disadvantage. YAML is very sensitive to whitespace and special characters, so the application may not load your dictionary properly. Ruby files will crash your application on first request, so you may easily find what's wrong. (If you encounter any "weird issues" with YAML dictionaries, try putting the relevant portion of your dictionary into a Ruby file.)
+If your translations are stored in YAML files, certain keys must be escaped. They are:
+
+* true, on, yes
+* false, off, no
+
+Examples:
+
+```erb
+# confing/locales/en.yml
+en:
+ success:
+ 'true': 'True!'
+ 'on': 'On!'
+ 'false': 'False!'
+ failure:
+ true: 'True!'
+ off: 'Off!'
+ false: 'False!'
+```
+
+```ruby
+I18n.t 'success.true' # => 'True!'
+I18n.t 'success.on' # => 'On!'
+I18n.t 'success.false' # => 'False!'
+I18n.t 'failure.false' # => Translation Missing
+I18n.t 'failure.off' # => Translation Missing
+I18n.t 'failure.true' # => Translation Missing
+```
+
### Passing Variables to Translations
One key consideration for successfully internationalizing an application is to
diff --git a/railties/lib/rails/generators/rails/app/templates/config/locales/en.yml b/railties/lib/rails/generators/rails/app/templates/config/locales/en.yml
index 0653957166..decc5a8573 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/locales/en.yml
+++ b/railties/lib/rails/generators/rails/app/templates/config/locales/en.yml
@@ -16,6 +16,16 @@
#
# This would use the information in config/locales/es.yml.
#
+# The following keys must be escaped otherwise they will not be retrieved by
+# the default I18n backend:
+#
+# true, false, on, off, yes, no
+#
+# Instead, surround them with single quotes.
+#
+# en:
+# 'true': 'foo'
+#
# To learn more, please read the Rails Internationalization guide
# available at http://guides.rubyonrails.org/i18n.html.