I use this guide: http://edgeguides.rubyonrails.org/i18n.html
What I would like:
/aboutgoes into pages#aboutdefault by default en.
/en/aboutgoes into pages#aboutwith locale en.
/es/aboutgoes into pages#aboutwith locale es.
What I get:
/aboutgoes into root_pathwith locale about.
/en/aboutgoes into pages#aboutwith locale en.
/es/aboutgoes into pages#aboutwith locale es.
Here is the code:
match '/:locale' => 'pages#news'
scope "(:locale)", :locale => /en|es/ do
match '/abcd' => 'pages#abcd'
match '/plan' => 'pages#plan'
match '/about' => 'pages#about'
match '/history' => 'pages#history'
match '/projects' => 'pages#projects'
match '/donate' => 'pages#donate'
match '/opportunities' => 'pages#opportunities'
match '/board' => 'pages#board'
end
root :to => "pages#news"
before_filter :set_locale
def set_locale
I18n.locale = params[:locale]
end
def default_url_options(options={})
{ :locale => I18n.locale }
end
If I read the manual correctly, section 2.5 says that I should have access to /aboutand download it by default.
From 2.5:
scope "(:locale)", :locale => /en|nl/ do
resources :books
end
With this approach, you will not get a routing error when accessing your resources such as http: // localhost: 3001 / books without a locale. This is useful when you want to use the default locale when one is not specified.