2011-05-03 33 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

相关问题