Reputation: 3341
I18n works as expected locally but not on heroku. It always shows english even if the browser is set to pt-BR. We set the locale in a before filter:
class ApplicationController < ActionController::Base
before_filter :set_locale
private
def set_locale
I18n.set_preferred_locale(env.http_accept_language)
end
end
module I18n
class << self
def set_preferred_locale(http_accept_language)
locale = http_accept_language.preferred_language_from(I18n.available_locales)
if locale.present?
I18n.locale = locale
I18n.default_locale = locale #added based on some stackflow answer about heroku and I18n
end
end
end
end
I have confirmed through the logger that I18n.locale has the correct value (pt-BR) in views but translations are still coming in english.
I have also tried as a test just setting directly to 'pt-BR' and still get the same result:
class ApplicationController < ActionController::Base
before_filter :set_locale
private
def set_locale
I18n.locale = 'pt-BR'
end
end
Upvotes: 0
Views: 1040
Reputation: 41
Worked for me, i have opened any file and save it with nobomb
Upvotes: 0
Reputation: 3341
Turns out I was setting it up fine. The issue was that there was a byte order mark in my pt-BR.yml. Apparently heroku can't load language files with them - heroku not loading language file.
I used vim to remove the marker with:
:set nobomb
:w
Upvotes: 3