5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-10-05 08:26:56 +00:00

Merge branch 'cambiar-idioma-desde-login' into panel.sutty.nl

This commit is contained in:
f 2022-08-27 19:31:28 -03:00
commit 442778b2b0
5 changed files with 22 additions and 8 deletions

View file

@ -56,7 +56,7 @@ class ApplicationController < ActionController::Base
# corresponde con el idioma de los artículos, porque puede querer # corresponde con el idioma de los artículos, porque puede querer
# traducirlos. # traducirlos.
def set_locale(&action) def set_locale(&action)
I18n.with_locale(current_locale(include_params: false), &action) I18n.with_locale(current_locale(include_params: params[:controller].start_with?('devise')), &action)
end end
# Muestra una página 404 # Muestra una página 404

View file

@ -9,6 +9,8 @@ class Usuarie < ApplicationRecord
validates_uniqueness_of :email validates_uniqueness_of :email
validates_with EmailAddress::ActiveRecordValidator, field: :email validates_with EmailAddress::ActiveRecordValidator, field: :email
before_create :lang_from_locale!
has_many :roles has_many :roles
has_many :sites, through: :roles has_many :sites, through: :roles
has_many :blazer_audits, foreign_key: 'user_id', class_name: 'Blazer::Audit' has_many :blazer_audits, foreign_key: 'user_id', class_name: 'Blazer::Audit'
@ -38,4 +40,11 @@ class Usuarie < ApplicationRecord
increment_failed_attempts increment_failed_attempts
lock_access! if attempts_exceeded? && !access_locked? lock_access! if attempts_exceeded? && !access_locked?
end end
private
def lang_from_locale!
binding.pry
self.lang = I18n.locale.to_s
end
end end

View file

@ -8,7 +8,7 @@
= form_for(resource, = form_for(resource,
as: resource_name, as: resource_name,
url: registration_path(resource_name)) do |f| url: registration_path(resource_name, params: { locale: params[:locale] })) do |f|
= render 'devise/shared/error_messages', resource: resource = render 'devise/shared/error_messages', resource: resource

View file

@ -1,35 +1,37 @@
%hr/ %hr/
- locale = params.permit(:locale)
- if controller_name != 'sessions' - if controller_name != 'sessions'
= link_to t('.sign_in'), new_session_path(resource_name) = link_to t('.sign_in'), new_session_path(resource_name, params: locale)
%br/ %br/
- if devise_mapping.registerable? && controller_name != 'registrations' - if devise_mapping.registerable? && controller_name != 'registrations'
= link_to t('.sign_up'), new_registration_path(resource_name), = link_to t('.sign_up'), new_registration_path(resource_name, params: locale),
class: 'btn btn-lg btn-block btn-success' class: 'btn btn-lg btn-block btn-success'
%br/ %br/
- if devise_mapping.recoverable? - if devise_mapping.recoverable?
- unless %w[passwords registrations].include?(controller_name) - unless %w[passwords registrations].include?(controller_name)
= link_to t('.forgot_your_password'), = link_to t('.forgot_your_password'),
new_password_path(resource_name) new_password_path(resource_name, params: locale)
%br/ %br/
- if devise_mapping.confirmable? && controller_name != 'confirmations' - if devise_mapping.confirmable? && controller_name != 'confirmations'
= link_to t('.didn_t_receive_confirmation_instructions'), = link_to t('.didn_t_receive_confirmation_instructions'),
new_confirmation_path(resource_name) new_confirmation_path(resource_name, params: locale)
%br/ %br/
- if devise_mapping.lockable? - if devise_mapping.lockable?
- if resource_class.unlock_strategy_enabled?(:email) - if resource_class.unlock_strategy_enabled?(:email)
- if controller_name != 'unlocks' - if controller_name != 'unlocks'
= link_to t('.didn_t_receive_unlock_instructions'), = link_to t('.didn_t_receive_unlock_instructions'),
new_unlock_path(resource_name) new_unlock_path(resource_name, params: locale)
%br/ %br/
- if devise_mapping.omniauthable? - if devise_mapping.omniauthable?
- resource_class.omniauth_providers.each do |provider| - resource_class.omniauth_providers.each do |provider|
= link_to t('.sign_in_with_provider', = link_to t('.sign_in_with_provider',
provider: OmniAuth::Utils.camelize(provider)), provider: OmniAuth::Utils.camelize(provider)),
omniauth_authorize_path(resource_name, provider) omniauth_authorize_path(resource_name, provider, params: locale)
%br/ %br/

View file

@ -22,3 +22,6 @@
%li.nav-item %li.nav-item
= link_to t('.logout'), main_app.destroy_usuarie_session_path, = link_to t('.logout'), main_app.destroy_usuarie_session_path,
method: :delete, role: 'button', class: 'btn' 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}"