Skip to content

Commit

Permalink
Use Devise translations when inheriting from core controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
rosenfeld committed Jan 7, 2015
1 parent d6972ab commit d87dfba
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* `RegistrationsController#new` and `SessionsController#new` now yields the
current resource (by @mtarnovan, @deivid-rodriguez)
* Password length validation is now limited to 72 characters for newer apps (by @lleger)
* Controllers inheriting from any Devise core controller will now use appropriate translations.
The i18n scope can be overridden in `translation_scope`.

### 3.4.1 - 2014-10-29

Expand Down
4 changes: 4 additions & 0 deletions app/controllers/devise/confirmations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@ def after_confirmation_path_for(resource_name, resource)
new_session_path(resource_name)
end
end

def translation_scope
'devise.confirmations'
end
end
4 changes: 4 additions & 0 deletions app/controllers/devise/omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ def failure_message
def after_omniauth_failure_path_for(scope)
new_session_path(scope)
end

def translation_scope
'devise.omniauth_callbacks'
end
end
4 changes: 4 additions & 0 deletions app/controllers/devise/passwords_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,8 @@ def unlockable?(resource)
resource.respond_to?(:unlock_strategy_enabled?) &&
resource.unlock_strategy_enabled?(:email)
end

def translation_scope
'devise.passwords'
end
end
4 changes: 4 additions & 0 deletions app/controllers/devise/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,8 @@ def sign_up_params
def account_update_params
devise_parameter_sanitizer.sanitize(:account_update)
end

def translation_scope
'devise.registrations'
end
end
4 changes: 4 additions & 0 deletions app/controllers/devise/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ def auth_options
{ scope: resource_name, recall: "#{controller_path}#new" }
end

def translation_scope
'devise.sessions'
end

private

# Check if there is no signed in user before doing the sign out.
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/devise/unlocks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,7 @@ def after_unlock_path_for(resource)
new_session_path(resource) if is_navigational_format?
end

def translation_scope
'devise.unlocks'
end
end
9 changes: 8 additions & 1 deletion app/controllers/devise_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,20 @@ def devise_i18n_options(options)

# Get message for given
def find_message(kind, options = {})
options[:scope] = "devise.#{controller_name}"
options[:scope] = translation_scope
options[:default] = Array(options[:default]).unshift(kind.to_sym)
options[:resource_name] = resource_name
options = devise_i18n_options(options)
I18n.t("#{options[:resource_name]}.#{kind}", options)
end

# Controllers inheriting DeviseController are advised to override this
# method so that other controllers inheriting from them would use
# existing translations.
def translation_scope
"devise.#{controller_name}"
end

def clean_up_passwords(object)
object.clean_up_passwords if object.respond_to?(:clean_up_passwords)
end
Expand Down

0 comments on commit d87dfba

Please sign in to comment.