问题
So, everything works fine locally, but at heroku it changes to :en
Fire up console on both environments:
Heroku:
heroku console --app myapp
Local:
rails c
Then play around
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
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.
FYI: I don't programatically set I18n.locale anywhere. staging.rb is plain.
回答1:
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.
回答2:
What version of Ruby on Rails are you using? I'm not positive about 2.x, but in Rails 3 you can set the default locale in config/application.rb
using config.i18n.default_locale = :en
. (This is the line, commented out by default.)
来源:https://stackoverflow.com/questions/5156765/heroku-i18n-locale-is-different-from-default-locale-works-fine-locally