heroku I18n 语言环境与 default_locale 不同,在本地运行良好 [英] heroku I18n locale is different from default_locale, works fine locally
问题描述
所以,在本地一切正常,但在 heroku 中它变为 :en
So, everything works fine locally, but at heroku it changes to :en
在两种环境中启动控制台:
Fire up console on both environments:
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.
Just doing I18n.locale = :nb
in the console fixed the problem ATM, and when I refresh in different browsers, it works ok. But on redeploy, it's back to :en.
我也必须在初始化程序中设置语言环境吗?我很困惑.
Do I have to set locale in initilizer too? I'm confused.
仅供参考:我不会在任何地方以编程方式设置 I18n.locale.staging.rb 很简单.
FYI: I don't programatically set I18n.locale anywhere. staging.rb is plain.
推荐答案
帮助直接设置语言环境.
It helped setting locale directly.
config.i18n.default_locale = :nb
#Adding the below makes it work as expected at heroku
config.i18n.locale = :nb
如果您有更好的解决方案,请告诉我,您将获得支持和接受的答案.
If you have a better solution, please let me know and you'll get upvote and accepted answer.
这篇关于heroku I18n 语言环境与 default_locale 不同,在本地运行良好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!