【问题标题】:heroku I18n locale is different from default_locale, works fine locallyheroku I18n 语言环境与 default_locale 不同,在本地运行良好
【发布时间】:2011-03-01 15:47:03
【问题描述】:

所以,在本地一切正常,但在 heroku 中它变为 :en

在两种环境中启动控制台:

Heroku:

heroku console --app myapp

本地:

rails c

然后玩弄

Heroku: > I18n.l Time.now
=> "Tue, 01 Mar 2011 06:43:58 -0800"
Local:  > I18n.l Time.now
 => "tirsdag,  1. mars 2011, 15:43"

Heroku: > I18n.default_locale
 => :nb
Local:  > I18n.default_locale
 => :nb

#after a lot more trial and error, I find this:
Heroku: > I18n.locale
=> :en
Local:  > I18n.locale
=> :nb

只需在控制台中执行I18n.locale = :nb 即可解决问题 ATM,当我在不同的浏览器中刷新时,它可以正常工作。但是在重新部署时,它又回到了 :en。

我也必须在初始化程序中设置语言环境吗?我很困惑。

仅供参考:我不会在任何地方以编程方式设置 I18n.locale。 staging.rb 很简单。

【问题讨论】:

    标签: ruby-on-rails internationalization heroku


    【解决方案1】:

    它有助于直接设置语言环境。

    config.i18n.default_locale = :nb
    #Adding the below makes it work as expected at heroku
    config.i18n.locale = :nb 
    

    如果您有更好的解决方案,请告诉我,您将获得支持和接受的答案。

    【讨论】:

    • 这个有效!即使它没有任何意义:P default_locale 应该可以工作....
    【解决方案2】:

    您使用的是哪个版本的 Ruby on Rails?我对 2.x 并不肯定,但在 Rails 3 中,您可以使用 config.i18n.default_locale = :enconfig/application.rb 中设置默认语言环境。 (This is the line,默认注释掉。)

    【讨论】:

    • 我设置了 config.i18n.default_locale = :nb,你在我的终端输出中看到的结果。 I18n.default_locale 在两种环境中都生成 :nb。
    • 啊,对不起!再次阅读问题,这很清楚。仔细检查在config/application.rbconfig/environment.rb 中,您使用config.i18n.default_locale 而不是I18n.default_locale 设置区域设置。另请参阅this SO answer 了解替代方案。
    猜你喜欢
    • 2019-04-23
    • 1970-01-01
    • 2021-11-13
    • 1970-01-01
    • 1970-01-01
    • 2013-09-22
    • 1970-01-01
    • 2011-02-28
    • 1970-01-01
    相关资源
    最近更新 更多