aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKir Shatrov <razor.psp@gmail.com>2011-09-16 06:44:04 -0700
committerKir Shatrov <razor.psp@gmail.com>2011-09-16 06:44:04 -0700
commit9f0db93250b74f788b15e7f8e227bd173ba4cf6c (patch)
treee25bbc1df8da3e1c2c5ab9ec0bf9ba2c0cc9f990
parent28677014a4f8121272a17870246507e86e46837c (diff)
parent302e570777b1ca8f537c96628334dcbe8a94d83f (diff)
downloadrails-9f0db93250b74f788b15e7f8e227bd173ba4cf6c.tar.gz
rails-9f0db93250b74f788b15e7f8e227bd173ba4cf6c.tar.bz2
rails-9f0db93250b74f788b15e7f8e227bd173ba4cf6c.zip
Merge pull request #68 from kirs/master
Paragraph about using variables in I18n translations was added to I18n Guide
-rw-r--r--railties/guides/source/i18n.textile14
1 files changed, 14 insertions, 0 deletions
diff --git a/railties/guides/source/i18n.textile b/railties/guides/source/i18n.textile
index 76cd14d479..a35cd6c506 100644
--- a/railties/guides/source/i18n.textile
+++ b/railties/guides/source/i18n.textile
@@ -365,6 +365,20 @@ 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.)
+h4. Passing variables into the translation
+
+You may use translation with parameters, if you want.
+
+<ruby>
+# app/views/home/index.html.erb
+<h1><%=t 'greet_username', :user => "Bill", :message => "Goodbye" %></h1>
+<h1><%=t 'greet_username', :user => "DHH", :message => "Hello" %></h1>
+
+# config/locales/en.yml
+en:
+ greet_username: "%{message}, %{user}!"
+</ruby>
+
h4. Adding Date/Time Formats
OK! Now let's add a timestamp to the view, so we can demo the *date/time localization* feature as well. To localize the time format you pass the Time object to +I18n.l+ or (preferably) use Rails' +#l+ helper. You can pick a format by passing the +:format+ option -- by default the +:default+ format is used.