mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-26 19:46:23 +00:00
Merge branch 'cambiar-idioma-desde-login' into panel.sutty.nl
This commit is contained in:
commit
c8e8791da2
11 changed files with 27 additions and 15 deletions
|
@ -46,17 +46,19 @@ class ApplicationController < ActionController::Base
|
|||
# defecto.
|
||||
#
|
||||
# Esto se refiere al idioma de la interfaz, no de los artículos.
|
||||
def current_locale(include_params: true, site: nil)
|
||||
return params[:locale] if include_params && params[:locale].present?
|
||||
#
|
||||
# @return [String,Symbol]
|
||||
def current_locale
|
||||
session[:locale] = params[:change_locale_to] if params[:change_locale_to].present?
|
||||
|
||||
current_usuarie&.lang || I18n.locale
|
||||
session[:locale] || current_usuarie&.lang || I18n.locale
|
||||
end
|
||||
|
||||
# El idioma es el preferido por le usuarie, pero no necesariamente se
|
||||
# corresponde con el idioma de los artículos, porque puede querer
|
||||
# traducirlos.
|
||||
def set_locale(&action)
|
||||
I18n.with_locale(current_locale(include_params: params[:controller].start_with?('devise')), &action)
|
||||
I18n.with_locale(current_locale, &action)
|
||||
end
|
||||
|
||||
# Muestra una página 404
|
||||
|
@ -88,4 +90,12 @@ class ApplicationController < ActionController::Base
|
|||
def prepare_exception_notifier
|
||||
request.env['exception_notifier.exception_data'] = { usuarie: current_usuarie }
|
||||
end
|
||||
|
||||
# Olvidar el idioma elegido antes de iniciar la sesión y reenviar a
|
||||
# los sitios en el idioma de le usuarie.
|
||||
def after_sign_in_path_for(resource)
|
||||
session[:locale] = nil
|
||||
|
||||
sites_path
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
%p= t('.greeting', recipient: @email)
|
||||
%p= t('.instruction')
|
||||
%p= link_to t('.action'), confirmation_url(@resource, confirmation_token: @token)
|
||||
%p= link_to t('.action'), confirmation_url(@resource, confirmation_token: @token, change_locale_to: @resource.lang)
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
\
|
||||
= t('.instruction')
|
||||
\
|
||||
= confirmation_url(@resource, confirmation_token: @token)
|
||||
= confirmation_url(@resource, confirmation_token: @token, change_locale_to: @resource.lang)
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
%p= site.description
|
||||
|
||||
%p= link_to t('devise.mailer.invitation_instructions.accept'),
|
||||
accept_invitation_url(@resource, invitation_token: @token)
|
||||
accept_invitation_url(@resource, invitation_token: @token, change_locale_to: @resource.lang)
|
||||
|
||||
- if @resource.invitation_due_at
|
||||
%p= t('devise.mailer.invitation_instructions.accept_until',
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
\
|
||||
= site.description
|
||||
\
|
||||
= accept_invitation_url(@resource, invitation_token: @token)
|
||||
= accept_invitation_url(@resource, invitation_token: @token, change_locale_to: @resource.lang)
|
||||
\
|
||||
- if @resource.invitation_due_at
|
||||
= t('devise.mailer.invitation_instructions.accept_until',
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
%p= t('.greeting', recipient: @resource.email)
|
||||
%p= t('.instruction')
|
||||
%p= link_to t('.action'), edit_password_url(@resource, reset_password_token: @token)
|
||||
%p= link_to t('.action'), edit_password_url(@resource, reset_password_token: @token, change_locale_to: @resource.lang)
|
||||
%p= t('.instruction_2')
|
||||
%p= t('.instruction_3')
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
\
|
||||
= t('.instruction')
|
||||
\
|
||||
= edit_password_url(@resource, reset_password_token: @token)
|
||||
= edit_password_url(@resource, reset_password_token: @token, change_locale_to: @resource.lang)
|
||||
\
|
||||
= t('.instruction_2')
|
||||
\
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
%p= t('.greeting', recipient: @resource.email)
|
||||
%p= t('.message')
|
||||
%p= t('.instruction')
|
||||
%p= link_to t('.action'), unlock_url(@resource, unlock_token: @token)
|
||||
%p= link_to t('.action'), unlock_url(@resource, unlock_token: @token, change_locale_to: @resource.lang)
|
||||
|
|
|
@ -4,4 +4,4 @@
|
|||
\
|
||||
= t('.instruction')
|
||||
\
|
||||
= unlock_url(@resource, unlock_token: @token)
|
||||
= unlock_url(@resource, unlock_token: @token, change_locale_to: @resource.lang)
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
- locale = params.permit(:locale)
|
||||
|
||||
- if controller_name != 'sessions'
|
||||
= link_to t('.sign_in'), new_session_path(resource_name, params: locale)
|
||||
= link_to t('.sign_in'), new_session_path(resource_name, params: locale),
|
||||
class: 'btn btn-lg btn-block btn-success'
|
||||
%br/
|
||||
|
||||
- if devise_mapping.registerable? && controller_name != 'registrations'
|
||||
|
|
|
@ -23,5 +23,6 @@
|
|||
= link_to t('.logout'), main_app.destroy_usuarie_session_path,
|
||||
method: :delete, role: 'button', class: 'btn'
|
||||
- else
|
||||
- other_locale = I18n.available_locales.find { |locale| locale != I18n.locale }
|
||||
= link_to t(other_locale), "?locale=#{other_locale}"
|
||||
- I18n.available_locales.each do |locale|
|
||||
- next if locale == I18n.locale
|
||||
= link_to t(locale), "?change_locale_to=#{locale}"
|
||||
|
|
Loading…
Reference in a new issue