2

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.

oma
  • 38,642
  • 11
  • 71
  • 99

2 Answers2

9

It helped setting locale directly:

config.i18n.default_locale = :nb
#Adding the below makes it work as expected at heroku
config.i18n.locale = :nb 
halfer
  • 19,824
  • 17
  • 99
  • 186
oma
  • 38,642
  • 11
  • 71
  • 99
0

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.)

Michelle Tilley
  • 157,729
  • 40
  • 374
  • 311
  • I have set config.i18n.default_locale = :nb, and the results you see in my terminal output. I18n.default_locale produces :nb at both environments. – oma Mar 04 '11 at 14:21
  • Ah, sorry! Reading the question again, that is clear. Double check that in `config/application.rb` or `config/environment.rb`, you're setting the locale with `config.i18n.default_locale` instead of `I18n.default_locale`. Also see [this SO answer](http://stackoverflow.com/questions/2782007/heroku-and-i18n-problems/2783948#2783948) for alternatives. – Michelle Tilley Mar 04 '11 at 15:34