Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails + Devise + I18n: how to set locale?

I use before_filter in ApplicationController to set locale for my application:

class ApplicationController < ActionController::Base
  protect_from_forgery
  before_filter :set_locale

  def set_locale
    I18n.locale = request.compatible_language_from ["uk", "ru", "de", "en"]
  end
end

It works for controllers that are written by me. But all devise's messages are still English.

Setting config.i18n.default_locale = "uk" (or other) in config/application.rb works, so I guess that the trouble is that devise's controller does not use my before_filter (possibly, it does not inherit ApplicationController at all (?)).

How to resolve this problem? How to make devise use my locale?

like image 913
frp Avatar asked Jul 04 '12 16:07

frp


1 Answers

Take a look at Devise Wiki https://github.com/plataformatec/devise/wiki/I18n They have lots of YML file samples.

If you still wanna write your own, try using something like this in your I18n files

en:
  devise:
    sessions:
      signed_in: 'Signed in successfully.'

More info on GitHub https://github.com/plataformatec/devise#i18n

like image 161
Felipe Skinner Avatar answered Sep 20 '22 18:09

Felipe Skinner