title: i18n Routing To Mounted Engine - Ignoring locale
body: <p>I have an application (my_test_app) with working i18n support built.  Currently, there are two language files available, FR &amp; EN, and if I toggle back and forth between them, everything works as I expect to see it for non-engine functions such as the User index/show/edit/delete (ISED) options.</p>
  
  <p>Within my_test_app I have a Rails Engine mounted (my_engine) which has a controller &amp; model set (engine_job).  So, a workable URL should be </p>
  
  <pre><code>http://0.0.0.0:3000/fr/my_engine/engine_job
  </code></pre>
  
  <p>No matter what language I choose, however, it always shows up in EN. Examining the parameters shows:</p>
  
  <pre><code>--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess
  locale: fr
  action: index
  controller: my_engine/engine_job
  </code></pre>
  
  <p>And yet the chosen translation is EN.</p>
  
  <p>my_test_app route.rb:</p>
  
  <pre><code>MyTestApp::Application.routes.draw do
  
    scope "(:locale)", locale: /#{I18n.available_locales.join("|")}/ do
      mount MyEngine::Engine, at: "/my_engine"
    end # scope locale
  
    match '*path', to: redirect("/#{I18n.default_locale}/%{path}"), constraints: lambda { |req| !req.path.starts_with? "/#{I18n.default_locale}/" and !req.path == "/#{I18n.default_locale}/"}
    match '', to: redirect("/#{I18n.default_locale}/")
  end
  </code></pre>
  
  <p>my_engine route.rb:</p>
  
  <pre><code>MyEngine::Engine.routes.draw do
    resources :my_jobs
  end
  </code></pre>
  
  <p>rake routes:</p>
  
  <pre><code>my_engine        (/:locale)/my_engine           MyEngine::Engine {:locale=&gt;/en|fr/}
                               /*path(.:format)                    :controller#:action
                               /                                   :controller#:action
                  users GET    (/:locale)/users(.:format)          users#index {:locale=&gt;/en|fr/}
                        POST   (/:locale)/users(.:format)          users#create {:locale=&gt;/en|fr/}
               new_user GET    (/:locale)/users/new(.:format)      users#new {:locale=&gt;/en|fr/}
              edit_user GET    (/:locale)/users/:id/edit(.:format) users#edit {:locale=&gt;/en|fr/}
                   user GET    (/:locale)/users/:id(.:format)      users#show {:locale=&gt;/en|fr/}
                        PUT    (/:locale)/users/:id(.:format)      users#update {:locale=&gt;/en|fr/}
                        DELETE (/:locale)/users/:id(.:format)      users#destroy {:locale=&gt;/en|fr/}
               sessions POST   (/:locale)/sessions(.:format)       sessions#create {:locale=&gt;/en|fr/}
            new_session GET    (/:locale)/sessions/new(.:format)   sessions#new {:locale=&gt;/en|fr/}
                session DELETE (/:locale)/sessions/:id(.:format)   sessions#destroy {:locale=&gt;/en|fr/}
                 signup        (/:locale)/signup(.:format)         users#new {:locale=&gt;/en|fr/}
                 signin        (/:locale)/signin(.:format)         sessions#new {:locale=&gt;/en|fr/}
                signout DELETE (/:locale)/signout(.:format)        sessions#destroy {:locale=&gt;/en|fr/}
                   help        (/:locale)/help(.:format)           static_pages#help {:locale=&gt;/en|fr/}
                  about        (/:locale)/about(.:format)          static_pages#about {:locale=&gt;/en|fr/}
                   root        /(:locale)(.:format)                static_pages#home {:locale=&gt;/en|fr/}
  
  Routes for MyEngine::Engine {:locale=&gt;/en|fr/}:
      engine_jobs GET    /engine_jobs(.:format)          my_engine/engine_jobs#index
                  POST   /engine_jobs(.:format)          my_engine/engine_jobs#create
   new_engine_job GET    /engine_jobs/new(.:format)      my_engine/engine_jobs#new
  edit_engine_job GET    /engine_jobs/:id/edit(.:format) my_engine/engine_jobs#edit
       engine_job GET    /engine_jobs/:id(.:format)      my_engine/engine_jobs#show
                  PUT    /engine_jobs/:id(.:format)      my_engine/engine_jobs#update
                  DELETE /engine_jobs/:id(.:format)      my_engine/engine_jobs#destroy
  </code></pre>
  
  <p>Further, any links clicked within the Engine set the language to EN.  A few web searches shed no real light as to what might be happening here, since all i18n examples I could find do not involve mounted engines.  </p>
  
  <p>EDIT: show code to set default locale
  my_test_app/app/controllers/application_controller.rb:</p>
  
  <pre><code>class ApplicationController &lt; ActionController::Base
    protect_from_forgery
    helper MyEngine::Engine.helpers
  
    ActiveRecord::Base.verify_active_connections!
  
    before_filter :set_locale
  
    private
      def set_locale
        I18n.locale = params[:locale] || I18n.default_locale
        Rails.application.routes.default_url_options[:locale]= I18n.locale
        logger.debug "My_Test_App:  default_url_options is passed options: #{Rails.application.routes.default_url_options.inspect}\n"
        # current_user.locale
        # request.subdomain
        # request.env["HTTP_ACCEPT_LANGUAGE"]
        # request.remote_ip
      end # set_locale
  
  end # class ApplicationController
  </code></pre>
  
  <p>/EDIT</p>
  
  <p>EDIT2 (Route Map after changes suggested by Pierre Aug 9 at 15:59):</p>
  
  <p>An application route yeilds <code>http://0.0.0.0:3000/en/users</code> with <code>"locale"=&gt;"en"</code>.  A Helper created engine route looks like <code>http://0.0.0.0:3000/my_engine?locale=en/engine_jobs</code> and yeilds <code>No route matches [GET] "/my_engine"</code>.</p>
  
  <pre><code>my_engine_plugin        /my_engine                     MyEnginePlugin::Engine
                  users GET    (/:locale)/users(.:format)          users#index {:locale=&gt;/en|fr/}
                        POST   (/:locale)/users(.:format)          users#create {:locale=&gt;/en|fr/}
               new_user GET    (/:locale)/users/new(.:format)      users#new {:locale=&gt;/en|fr/}
              edit_user GET    (/:locale)/users/:id/edit(.:format) users#edit {:locale=&gt;/en|fr/}
                   user GET    (/:locale)/users/:id(.:format)      users#show {:locale=&gt;/en|fr/}
                        PUT    (/:locale)/users/:id(.:format)      users#update {:locale=&gt;/en|fr/}
                        DELETE (/:locale)/users/:id(.:format)      users#destroy {:locale=&gt;/en|fr/}
               sessions POST   (/:locale)/sessions(.:format)       sessions#create {:locale=&gt;/en|fr/}
            new_session GET    (/:locale)/sessions/new(.:format)   sessions#new {:locale=&gt;/en|fr/}
                session DELETE (/:locale)/sessions/:id(.:format)   sessions#destroy {:locale=&gt;/en|fr/}
                 signup        (/:locale)/signup(.:format)         users#new {:locale=&gt;/en|fr/}
                 signin        (/:locale)/signin(.:format)         sessions#new {:locale=&gt;/en|fr/}
                signout DELETE (/:locale)/signout(.:format)        sessions#destroy {:locale=&gt;/en|fr/}
                   help        (/:locale)/help(.:format)           static_pages#help {:locale=&gt;/en|fr/}
                  about        (/:locale)/about(.:format)          static_pages#about {:locale=&gt;/en|fr/}
                   root        /(:locale)(.:format)                static_pages#home {:locale=&gt;/en|fr/}
  
  Routes for MyEnginePlugin::Engine:
      engine_jobs GET    (/:locale)/engine_jobs(.:format)          my_engine_plugin/engine_jobs#index {:locale=&gt;/en|fr/}
                       POST   (/:locale)/engine_jobs(.:format)          my_engine_plugin/engine_jobs#create {:locale=&gt;/en|fr/}
   new_engine_job GET    (/:locale)/engine_jobs/new(.:format)      my_engine_plugin/engine_jobs#new {:locale=&gt;/en|fr/}
  edit_engine_job GET    (/:locale)/engine_jobs/:id/edit(.:format) my_engine_plugin/engine_jobs#edit {:locale=&gt;/en|fr/}
       engine_job GET    (/:locale)/engine_jobs/:id(.:format)      my_engine_plugin/engine_jobs#show {:locale=&gt;/en|fr/}
                       PUT    (/:locale)/engine_jobs/:id(.:format)      my_engine_plugin/engine_jobs#update {:locale=&gt;/en|fr/}
                       DELETE (/:locale)/engine_jobs/:id(.:format)      my_engine_plugin/engine_jobs#destroy {:locale=&gt;/en|fr/}
  </code></pre>
  
  <p>/EDIT2 (Route Map after changes suggested by Pierre Aug 9 at 15:59)</p>
  
  <p>So, the question is what changes do I need to make to my routes or engine to get this to work as expected?</p>
  
  <p>Thanks in advance for your time and suggestions!</p>