mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-16 15:41:42 +00:00
permitir a les usuaries elegir idioma y registrarse con ese
This commit is contained in:
parent
64e93506b7
commit
0afe4b6aba
5 changed files with 22 additions and 8 deletions
|
@ -54,7 +54,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
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
@ -36,4 +38,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
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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/
|
||||||
|
|
|
@ -22,3 +22,6 @@
|
||||||
%li.nav-item
|
%li.nav-item
|
||||||
= link_to t('.logout'), destroy_usuarie_session_path,
|
= link_to t('.logout'), 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}"
|
||||||
|
|
Loading…
Reference in a new issue