Search code examples
ruby-on-railslocale

Rails: set locale for a specific path


I want to specify locale for specific path.

in my whole application I have my default local e set to :es

 config.i18n.default_locale = :es

That works in the normal fashion for the whole application, I want to know how can I specify a specific locale for a set of paths...

I integrated a third party application called maily_herald, in order to make it's paths available for my application i have to add this line to my routes.rb file

mount MailyHerald::Webui::Engine => "/maily_webui"

the problem is that there are not translations for locale :es, so it does not work properly... I want to let all the paths under /maily_webui to have locale :en so the third party application will work in english while my application will still work in :es

any idea how to do this?


Solution

  • class ApplicationController < ActionController::Base
      .....
      before_filter :set_locale
    
    
      def set_locale
        if request.fullpath == "some_path"
          I18n.locale = :some_locale
        else
          I18n.locale = params[:locale] || I18n.default_locale
        end
      end
    
    end