Question

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
Was it helpful?

Solution

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

OTHER TIPS

Worked for me, i have opened any file and save it with nobomb

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top