2011-05-03 36 views
0

我在開發中有一個雙語應用程序。我可以通過傳遞locale = en在開發中將語言環境更改爲英語,它在開發中工作,但不在heroku中。在Heroku中運行時無法更改Rails應用的區域設置在開發中運行良好

通過我下面插入我可以告訴現場實際的變化,但所有的內容在默認語言環境

application_controller.rb

class ApplicationController < ActionController::Base 
    protect_from_forgery 
    before_filter :set_locale 

    def set_locale  
    if %w(en pt-BR).include? params[:locale] 
     I18n.locale = params[:locale].to_sym 
    end 
    logger.info I18n.locale 
    end 
end 

的config/application.rb中

config.i18n.default_locale = :'pt-BR' 
config.i18n.locale = :'pt-BR' 
發出的記錄

回答

1

試試這個

class ApplicationController < ActionController::Base 
    protect_from_forgery 
    before_filter :set_locale 

    protected  
    def set_locale 
    if params[:locale].blank? 
     I18n.locale = :'pt-BR' 
    else 
     I18n.locale = params[:locale] 
    end 
    end 

    # ensure locale persists 
    def default_url_options(options={}) 
    {:locale => I18n.locale} 
    end 
end 

和routes.rb中

scope "(:locale)", :locale => /pt-BR|en/ do 
    resources :products # update this! 
    end 

感覺吸塵器有domain.tld/:locale/類型的路由,以及。

+0

感謝您發表該答案。它爲我工作。 – Norto23 2012-06-04 10:39:31

+0

很高興聽到=) – 2012-06-06 23:10:42

相關問題