mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-16 13:21:41 +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
|
||||
# traducirlos.
|
||||
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
|
||||
|
||||
# Muestra una página 404
|
||||
|
|
|
@ -9,6 +9,8 @@ class Usuarie < ApplicationRecord
|
|||
validates_uniqueness_of :email
|
||||
validates_with EmailAddress::ActiveRecordValidator, field: :email
|
||||
|
||||
before_create :lang_from_locale!
|
||||
|
||||
has_many :roles
|
||||
has_many :sites, through: :roles
|
||||
|
||||
|
@ -36,4 +38,11 @@ class Usuarie < ApplicationRecord
|
|||
increment_failed_attempts
|
||||
lock_access! if attempts_exceeded? && !access_locked?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def lang_from_locale!
|
||||
binding.pry
|
||||
self.lang = I18n.locale.to_s
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
= form_for(resource,
|
||||
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
|
||||
|
||||
|
|
|
@ -1,35 +1,37 @@
|
|||
%hr/
|
||||
|
||||
- locale = params.permit(:locale)
|
||||
|
||||
- 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/
|
||||
|
||||
- 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'
|
||||
%br/
|
||||
|
||||
- if devise_mapping.recoverable?
|
||||
- unless %w[passwords registrations].include?(controller_name)
|
||||
= link_to t('.forgot_your_password'),
|
||||
new_password_path(resource_name)
|
||||
new_password_path(resource_name, params: locale)
|
||||
%br/
|
||||
|
||||
- if devise_mapping.confirmable? && controller_name != 'confirmations'
|
||||
= link_to t('.didn_t_receive_confirmation_instructions'),
|
||||
new_confirmation_path(resource_name)
|
||||
new_confirmation_path(resource_name, params: locale)
|
||||
%br/
|
||||
|
||||
- if devise_mapping.lockable?
|
||||
- if resource_class.unlock_strategy_enabled?(:email)
|
||||
- if controller_name != 'unlocks'
|
||||
= link_to t('.didn_t_receive_unlock_instructions'),
|
||||
new_unlock_path(resource_name)
|
||||
new_unlock_path(resource_name, params: locale)
|
||||
%br/
|
||||
|
||||
- if devise_mapping.omniauthable?
|
||||
- resource_class.omniauth_providers.each do |provider|
|
||||
= link_to t('.sign_in_with_provider',
|
||||
provider: OmniAuth::Utils.camelize(provider)),
|
||||
omniauth_authorize_path(resource_name, provider)
|
||||
omniauth_authorize_path(resource_name, provider, params: locale)
|
||||
%br/
|
||||
|
|
|
@ -22,3 +22,6 @@
|
|||
%li.nav-item
|
||||
= link_to t('.logout'), 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}"
|
||||
|
|
Loading…
Reference in a new issue