aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnil Wadghule <anildigital@gmail.com>2010-04-13 12:25:44 +0530
committerAnil Wadghule <anildigital@gmail.com>2010-04-13 12:25:44 +0530
commitfe0b52befb99e247c5cb98aceaa660dce34cfc47 (patch)
tree3332558b4f7f96bab90e48133ca99bff9a456564
parent3f0097c7157e4a328f87cdf80ab6330c39b6d90f (diff)
downloadrails-fe0b52befb99e247c5cb98aceaa660dce34cfc47.tar.gz
rails-fe0b52befb99e247c5cb98aceaa660dce34cfc47.tar.bz2
rails-fe0b52befb99e247c5cb98aceaa660dce34cfc47.zip
Changes in guide as per Rails 3 features
-rw-r--r--railties/guides/source/i18n.textile30
1 files changed, 15 insertions, 15 deletions
diff --git a/railties/guides/source/i18n.textile b/railties/guides/source/i18n.textile
index cfaa573fa0..01e3380ee4 100644
--- a/railties/guides/source/i18n.textile
+++ b/railties/guides/source/i18n.textile
@@ -97,19 +97,17 @@ The *translations load path* (+I18n.load_path+) is just a Ruby Array of paths to
NOTE: The backend will lazy-load these translations when a translation is looked up for the first time. This makes it possible to just swap the backend with something else even after translations have already been announced.
-The default +environment.rb+ files has instructions on how to add locales from another directory and how to set a different default locale. Just uncomment and edit the specific lines.
+The default +application.rb+ files has instructions on how to add locales from another directory and how to set a different default locale. Just uncomment and edit the specific lines.
<ruby>
-# The internationalization framework can be changed
-# to have another default locale (standard is :en) or more load paths.
-# All files from config/locales/*.rb,yml are added automatically.
-# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
+# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
+# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
</ruby>
h4. Optional: Custom I18n Configuration Setup
-For the sake of completeness, let's mention that if you do not want to use the +environment.rb+ file for some reason, you can always wire up things manually, too.
+For the sake of completeness, let's mention that if you do not want to use the +application.rb+ file for some reason, you can always wire up things manually, too.
To tell the I18n library where it can find your custom translation files you can specify the load path anywhere in your application - just make sure it gets run before any translations are actually looked up. You might also want to change the default locale. The simplest thing possible is to put the following into an initializer:
@@ -117,7 +115,7 @@ To tell the I18n library where it can find your custom translation files you can
# in config/initializers/locale.rb
# tell the I18n library where to find your translations
-I18n.load_path << Dir[Rails.root.join('lib', 'locale', '*.{rb,yml}')]
+I18n.load_path += Dir[Rails.root.join('lib', 'locale', '*.{rb,yml}')]
# set default locale to something other than :en
I18n.default_locale = :pt
@@ -125,7 +123,7 @@ I18n.default_locale = :pt
h4. Setting and Passing the Locale
-If you want to translate your Rails application to a *single language other than English* (the default locale), you can set I18n.default_locale to your locale in +environment.rb+ or an initializer as shown above, and it will persist through the requests.
+If you want to translate your Rails application to a *single language other than English* (the default locale), you can set I18n.default_locale to your locale in +application.rb+ or an initializer as shown above, and it will persist through the requests.
However, you would probably like to *provide support for more locales* in your application. In such case, you need to set and pass the locale between requests.
@@ -226,21 +224,23 @@ You probably want URLs to look like this: +www.example.com/en/books+ (which load
<ruby>
# config/routes.rb
-map.resources :books, :path_prefix => '/:locale'
+scope "/:locale" do
+ resources :books
+end
</ruby>
Now, when you call the +books_path+ method you should get +"/en/books"+ (for the default locale). An URL like +http://localhost:3001/nl/books+ should load the Netherlands locale, then, and following calls to +books_path+ should return +"/nl/books"+ (because the locale changed).
-Of course, you need to take special care of the root URL (usually "homepage" or "dashboard") of your application. An URL like +http://localhost:3001/nl+ will not work automatically, because the +map.root :controller => "dashboard"+ declaration in your +routes.rb+ doesn't take locale into account. (And rightly so: there's only one "root" URL.)
+Of course, you need to take special care of the root URL (usually "homepage" or "dashboard") of your application. An URL like +http://localhost:3001/nl+ will not work automatically, because the +root :to => "books#index"+ declaration in your +routes.rb+ doesn't take locale into account. (And rightly so: there's only one "root" URL.)
You would probably need to map URLs like these:
<ruby>
# config/routes.rb
-map.dashboard '/:locale', :controller => "dashboard"
+match '/:locale' => 'dashboard#index'
</ruby>
-Do take special care about the *order of your routes*, so this route declaration does not "eat" other ones. (You may want to add it directly before the +map.root+ declaration.)
+Do take special care about the *order of your routes*, so this route declaration does not "eat" other ones. (You may want to add it directly before the +root :to+ declaration.)
IMPORTANT: This solution has currently one rather big *downside*. Due to the _default_url_options_ implementation, you have to pass the +:id+ option explicitly, like this: +link_to 'Show', book_url(:id => book)+ and not depend on Rails' magic in code like +link_to 'Show', book+. If this should be a problem, have a look at two plugins which simplify work with routes in this way: Sven Fuchs's "routing_filter":http://github.com/svenfuchs/routing-filter/tree/master and Raul Murciano's "translate_routes":http://github.com/raul/translate_routes/tree/master. See also the page "How to encode the current locale in the URL":http://rails-i18n.org/wiki/wikipages/how-to-encode-the-current-locale-in-the-url in the Rails i18n Wiki.
@@ -287,8 +287,8 @@ You most probably have something like this in one of your applications:
<ruby>
# config/routes.rb
-ActionController::Routing::Routes.draw do |map|
- map.root :controller => 'home', :action => 'index'
+Yourapp::Application.routes.draw do |map|
+ root :to => "home#index"
end
# app/controllers/home_controller.rb
@@ -421,7 +421,7 @@ This way, you can separate model and model attribute names from text inside view
NOTE: The default locale loading mechanism in Rails does not load locale files in nested dictionaries, like we have here. So, for this to work, we must explicitly tell Rails to look further:
<ruby>
- # config/environment.rb
+ # config/application.rb
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')]
</ruby>