aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/i18n.md
diff options
context:
space:
mode:
authorJoshua Cody <josh@joshuacody.net>2014-05-05 17:48:53 -0500
committerJoshua Cody <josh@joshuacody.net>2014-05-06 14:37:28 -0500
commitd5f2c5c20e2f8f104a1e67ba81166874cc472b9e (patch)
tree1f5943583d2d867766bd4c97d87de5db47812f93 /guides/source/i18n.md
parentb6bab2af144d3f35ae2e1661286f2e35f43f5d3a (diff)
downloadrails-d5f2c5c20e2f8f104a1e67ba81166874cc472b9e.tar.gz
rails-d5f2c5c20e2f8f104a1e67ba81166874cc472b9e.tar.bz2
rails-d5f2c5c20e2f8f104a1e67ba81166874cc472b9e.zip
Include label value in i18n attribute lookup
Previously, only the object and method name from the label tag were used when looking up the translation for a label. If a value is given for the label, this ought to be additionally used. The following: # form.html.erb <%= form_for @post do |f| %> <%= f.label :type, value: "long" %> <% end %> # en.yml en: activerecord: attributes: post/long: "Long-form Post" Used to simply return "long", but now it will return "Long-form Post".
Diffstat (limited to 'guides/source/i18n.md')
-rw-r--r--guides/source/i18n.md13
1 files changed, 13 insertions, 0 deletions
diff --git a/guides/source/i18n.md b/guides/source/i18n.md
index c1b575c7b7..0eba3af6e8 100644
--- a/guides/source/i18n.md
+++ b/guides/source/i18n.md
@@ -712,6 +712,19 @@ en:
Then `User.model_name.human(count: 2)` will return "Dudes". With `count: 1` or without params will return "Dude".
+In the event you need to access nested attributes within a given model, you should nest these under `model/attribute` at the model level of your translation file:
+
+```yaml
+en:
+ activerecord:
+ attributes:
+ user/gender:
+ female: "Female"
+ male: "Male"
+```
+
+Then `User.human_attribute_name("gender.female")` will return "Female".
+
#### Error Message Scopes
Active Record validation error messages can also be translated easily. Active Record gives you a couple of namespaces where you can place your message translations in order to provide different messages and translation for certain models, attributes, and/or validations. It also transparently takes single table inheritance into account.