I've done some research on this topic already, but I don't seem to be able to figure it out.
I have followed the official guide to set up I18n, but I just don't get the default locale to be set properly (when no explicit locale is specified).
# routes.rb
require 'sidekiq/web'
Iq::Application.routes.draw do
scope "(:locale)", locale: /de|en/ do
# ...
end
end
# application_controller.rb
class ApplicationController < ActionController::Base
before_filter :set_language
def set_language
I18n.locale = params[:locale] || I18n.default_locale
end
def default_url_options(options = {})
options.merge!({ :locale => I18n.locale })
end
end
In the OS X console:
$ rake routes | grep user
...
user GET (/:locale)/users/:id(.:format) users#show {:locale=>/de|en/}
...
In the Rails console:
$ Rails c
$ app.users_path
=> "/users"
app.users_path locale: :de
=> "/de/users"
$ app.user_path User.first, locale: :de
=> "/de/users/509fc01d77bb1e6a050000a0"
$ app.user_path User.first
ActionController::RoutingError: No route matches {:action=>"show", :controller=>"users", :locale=>#<User _id: 509fc01d77bb1e6a050000a0, _type: nil, created_at: 2012-11-11 15:11:25 UTC, updated_at: 2012-11-11 15:11:25 UTC, deleted_at: nil, group: "administrator", language: "de", active: true, sign_in_count: 0, name: "sysadmin", email: "support@sientia.ch", encrypted_password: "$2a$10$n/b7sTmUjEMoZI/jvq2jPuaNQqo1R1zbAIPpko9HT9PERagXclrPK", reset_password_token: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, confirmation_token: nil, unconfirmed_email: nil, reset_password_sent_at: nil, remember_created_at: nil, confirmed_at: 2012-11-11 15:11:25 UTC, confirmation_sent_at: nil, current_sign_in_at: nil, last_sign_in_at: nil, save_vertical_menu_visibility_state: nil, contact_id: "509fc01d77bb1e6a0500008c", contact_name: "Sientia AG">}
from /Users/josh/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:532:in `raise_routing_error'
Why doesn't this work? What did I forget?
Thanks a lot for help, Josh