Use Devise translations when inheriting from core controllers

closes #3367
This commit is contained in:
Rodrigo Rosenfeld Rosas 2015-01-07 11:35:45 -02:00
parent 5eb9f18743
commit c2fb80d4d9
8 changed files with 33 additions and 1 deletions

View File

@ -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

View File

@ -44,4 +44,8 @@ class Devise::ConfirmationsController < DeviseController
new_session_path(resource_name)
end
end
def translation_scope
'devise.confirmations'
end
end

View File

@ -27,4 +27,8 @@ class Devise::OmniauthCallbacksController < DeviseController
def after_omniauth_failure_path_for(scope)
new_session_path(scope)
end
def translation_scope
'devise.omniauth_callbacks'
end
end

View File

@ -68,4 +68,8 @@ class Devise::PasswordsController < DeviseController
resource.respond_to?(:unlock_strategy_enabled?) &&
resource.unlock_strategy_enabled?(:email)
end
def translation_scope
'devise.passwords'
end
end

View File

@ -140,4 +140,8 @@ class Devise::RegistrationsController < DeviseController
def account_update_params
devise_parameter_sanitizer.sanitize(:account_update)
end
def translation_scope
'devise.registrations'
end
end

View File

@ -46,6 +46,10 @@ class Devise::SessionsController < DeviseController
{ 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.

View File

@ -43,4 +43,7 @@ class Devise::UnlocksController < DeviseController
new_session_path(resource) if is_navigational_format?
end
def translation_scope
'devise.unlocks'
end
end

View File

@ -167,13 +167,20 @@ MESSAGE
# 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