aboutsummaryrefslogtreecommitdiffstats
path: root/railties/doc/guides/source/i18n.txt
diff options
context:
space:
mode:
authorSven Fuchs <svenfuchs@artweb-design.de>2008-12-16 18:10:02 +0100
committerSven Fuchs <svenfuchs@artweb-design.de>2008-12-16 18:10:02 +0100
commitd6e6754ebe2a061d37b28262dcb0d784d913eaf8 (patch)
tree2f2d7f45d8cfcfc360437627aa948de460f220c5 /railties/doc/guides/source/i18n.txt
parentd736327e7d6e910f4c96580ccfcde482925c917f (diff)
downloadrails-d6e6754ebe2a061d37b28262dcb0d784d913eaf8.tar.gz
rails-d6e6754ebe2a061d37b28262dcb0d784d913eaf8.tar.bz2
rails-d6e6754ebe2a061d37b28262dcb0d784d913eaf8.zip
i18n guide: add screenshots and explain localize method
Diffstat (limited to 'railties/doc/guides/source/i18n.txt')
-rw-r--r--railties/doc/guides/source/i18n.txt47
1 files changed, 39 insertions, 8 deletions
diff --git a/railties/doc/guides/source/i18n.txt b/railties/doc/guides/source/i18n.txt
index 4f5c27647d..d2cfbdad5d 100644
--- a/railties/doc/guides/source/i18n.txt
+++ b/railties/doc/guides/source/i18n.txt
@@ -128,7 +128,9 @@ end
<p><%= flash[:notice] %></p>
-------------------------------------------------------
-TODO screenshot
+image:images/i18n/demo_untranslated.png[rails i18n demo untranslated]
+
+=== Adding Translations
Obviously there are two strings that are localized to English. In order to internationalize this code replace these strings with calls to Rails' #t helper with a key that makes sense for the translation:
@@ -148,7 +150,7 @@ end
When you now render this view it will show an error message that tells you that the translations for the keys :hello_world and :hello_flash are missing.
-TODO screenshot
+image:images/i18n/demo_translation_missing.png[rails i18n demo translation missing]
NOTE: Rails adds a +t+ (+translate+) helper method to your views so that you do not need to spell out +I18n.t+ all the time. Additionally this helper will catch missing translations and wrap the resulting error message into a &lt;span class="translation_missing"&gt;.
@@ -156,27 +158,56 @@ So let's add the missing translations (i.e. do the "localization" part):
[source, ruby]
-------------------------------------------------------
-# lib/locale/en.yml
+# config/locale/en.yml
en:
hello_world: Hello World
hello_flash: Hello Flash
-# lib/locale/pirate.yml
+# config/locale/pirate.yml
pirate:
hello_world: Ahoy World
hello_flash: Ahoy Flash
-------------------------------------------------------
-There you go. Your application now shows:
+There you go. Because you haven't changed the default_locale I18n will use English. Your application now shows:
+
+image:images/i18n/demo_translated_english.png[rails i18n demo translated to english]
+
+And when you change the URL to pass the pirate locale you get:
+
+image:images/i18n/demo_translated_pirate.png[rails i18n demo translated to pirate]
+
+NOTE You need to restart the server when you add new locale files.
-TODO screenshot
+=== Adding Date/Time formats
+
+Ok, 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.
[source, ruby]
-------------------------------------------------------
-I18n.t 'store.title'
-I18n.l Time.now
+# app/views/home/index.html.erb
+<h1><%=t :hello_world %></h1>
+<p><%= flash[:notice] %></p
+<p><%= l Time.now, :format => :short %></p>
-------------------------------------------------------
+And in our pirate translations file let's add a time format (it's already there in Rails' defaults for English):
+
+[source, ruby]
+-------------------------------------------------------
+# config/locale/pirate.yml
+pirate:
+ time:
+ formats:
+ short: "arrrround %H'ish"
+-------------------------------------------------------
+
+So that would give you:
+
+image:images/i18n/demo_localized_pirate.png[rails i18n demo localized time to pirate]
+
+NOTE Right now you might need to add some more date/time formats in order to make the I18n backend work as expected. See the http://github.com/svenfuchs/rails-i18n/tree/master/rails/locale[rails-i18n repository] for starting points.
+
== Overview of the I18n API features