permitir que les usuaries se cambien el idioma

This commit is contained in:
f 2019-08-02 15:58:15 -03:00
parent aebe5b6764
commit 48b85acace
No known key found for this signature in database
GPG key ID: 2AE5A13E321F953D
9 changed files with 93 additions and 38 deletions

View file

@ -5,8 +5,12 @@ class ApplicationController < ActionController::Base
include ExceptionHandler include ExceptionHandler
protect_from_forgery with: :exception protect_from_forgery with: :exception
before_action :configure_permitted_parameters, if: :devise_controller?
before_action :set_locale before_action :set_locale
layout :layout_by_usuarie
# No tenemos índice de sutty, vamos directamente a ver el listado de # No tenemos índice de sutty, vamos directamente a ver el listado de
# sitios # sitios
def index def index
@ -17,6 +21,14 @@ class ApplicationController < ActionController::Base
private private
def layout_by_usuarie
if current_usuarie
'application'
else
'devise'
end
end
# Encontrar un sitio por su nombre # Encontrar un sitio por su nombre
def find_site def find_site
id = params[:site_id] || params[:id] id = params[:site_id] || params[:id]
@ -50,6 +62,12 @@ class ApplicationController < ActionController::Base
end end
def set_locale def set_locale
I18n.locale = session[:lang] if session[:lang].present? I18n.locale = current_usuarie.lang
end
protected
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:account_update, keys: %i[lang])
end end
end end

View file

@ -1,42 +1,65 @@
.row
.col
= render 'layouts/breadcrumb',
crumbs: [link_to(t('.index'), sites_path), t('.title')]
.row.align-items-center.justify-content-center.full-height .row.align-items-center.justify-content-center.full-height
.col-md-6.align-self-center .col-md-6.align-self-center
%h2= t('.title', resource: resource.model_name.human) %h2= t('.title')
= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| = form_for(resource,
as: resource_name,
url: registration_path(resource_name),
html: { method: :put }) do |f|
= render 'devise/shared/error_messages', resource: resource = render 'devise/shared/error_messages', resource: resource
.form-group .form-group
= f.label :email = f.label :email
= f.email_field :email, autofocus: true, autocomplete: 'email', = f.email_field :email, autofocus: true, autocomplete: 'email',
class: 'form-control' class: 'form-control'
- if devise_mapping.confirmable? && resource.pending_reconfirmation? - if devise_mapping.confirmable? && resource.pending_reconfirmation?
%div= t('.currently_waiting_confirmation_for_email', email: resource.unconfirmed_email) %div
= t('.currently_waiting_confirmation_for_email',
email: resource.unconfirmed_email)
.form-group
= f.label :lang
= f.select :lang,
I18n.available_locales.map { |lang| [t(lang), lang] }, {},
class: 'form-control'
.form-group .form-group
= f.label :password = f.label :password
%i
(#{t('.leave_blank_if_you_don_t_want_to_change_it')})
= f.password_field :password, autocomplete: 'new-password', = f.password_field :password, autocomplete: 'new-password',
class: 'form-control' class: 'form-control', 'aria-describedby': 'password-help'
%small.text-muted.form-text#password-help
= t('.leave_blank_if_you_don_t_want_to_change_it')
- if @minimum_password_length - if @minimum_password_length
%em= t('devise.shared.minimum_password_length', count: @minimum_password_length) = t('devise.shared.minimum_password_length',
count: @minimum_password_length)
.form-group .form-group
= f.label :password_confirmation = f.label :password_confirmation
= f.password_field :password_confirmation, = f.password_field :password_confirmation,
autocomplete: 'new-password', autocomplete: 'new-password',
class: 'form-control' class: 'form-control'
.form-group .form-group
= f.label :current_password = f.label :current_password
%i
(#{t('.we_need_your_current_password_to_confirm_your_changes')})
= f.password_field :current_password, = f.password_field :current_password,
autocomplete: 'current-password', autocomplete: 'current-password',
class: 'form-control' required: true,
class: 'form-control',
'aria-describedby': 'current-password-help'
%small.text-muted.form-text#current-password-help
= t('.we_need_your_current_password_to_confirm_your_changes')
.actions .actions
= f.submit t('.update'), = f.submit t('.update'),
class: 'btn btn-lg btn-primary btn-block' class: 'btn btn-lg btn-primary btn-block'
%hr/
%h3= t('.cancel_my_account') %h3= t('.cancel_my_account')
%p %p
= t('.unhappy')
= button_to t('.cancel_my_account'), = button_to t('.cancel_my_account'),
registration_path(resource_name), registration_path(resource_name),
data: { confirm: t('.are_you_sure') }, data: { confirm: t('.are_you_sure') },
method: :delete method: :delete, class: 'btn btn-danger btn-block'
= link_to t('devise.shared.links.back'), :back

View file

@ -1,17 +1,20 @@
%nav{'aria-label': 'breadcrumb', role: 'navigation'} %nav{ 'aria-label': 'breadcrumb', role: 'navigation' }
%ol.breadcrumb %ol.breadcrumb
%li.breadcrumb-item %li.breadcrumb-item
= link_to destroy_usuarie_session_path, method: :delete, = link_to destroy_usuarie_session_path, method: :delete,
data: { toggle: 'tooltip' }, title: t('help.logout'), data: { toggle: 'tooltip' }, title: t('help.logout'),
role: 'button', class: 'btn-text' do role: 'button', class: 'btn-text' do
= fa_icon 'sign-out', title: t('help.logout') = fa_icon 'sign-out', title: t('help.logout')
%li.breadcrumb-item
= link_to edit_usuarie_registration_path,
data: { toggle: 'tooltip' }, title: t('help.usuarie.edit') do
= current_usuarie.email
- if @site.try(:persisted?) && (help = @site.try(:config).try(:dig, 'help')) - if @site.try(:persisted?) && (help = @site.try(:config).try(:dig, 'help'))
%li.breadcrumb-item= link_to t('.help'), help, target: '_blank' %li.breadcrumb-item= link_to t('.help'), help, target: '_blank'
- crumbs.compact.each do |crumb| - crumbs.compact.each do |crumb|
- if current_user.is_a? Invitadx
- if /\/sites/ =~ crumb
- next
- if crumb == crumbs.last - if crumb == crumbs.last
%li.breadcrumb-item.active{'aria-current': 'page'}= crumb %li.breadcrumb-item.active{ 'aria-current': 'page' }= crumb
- else - else
%li.breadcrumb-item= crumb %li.breadcrumb-item= crumb

View file

@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
Rails.application.configure do Rails.application.configure do
config.i18n.available_locales = %i[es en ar] config.i18n.available_locales = %i[es en]
config.i18n.default_locale = :es config.i18n.default_locale = :es
end end

View file

@ -93,14 +93,14 @@ en:
registrations: registrations:
destroyed: Bye! Your account has been successfully cancelled. We hope to see you again soon. destroyed: Bye! Your account has been successfully cancelled. We hope to see you again soon.
edit: edit:
index: 'Back to sites'
are_you_sure: Are you sure? are_you_sure: Are you sure?
cancel_my_account: Cancel my account cancel_my_account: Cancel my account
currently_waiting_confirmation_for_email: 'Currently waiting confirmation for: %{email}' currently_waiting_confirmation_for_email: 'Currently waiting confirmation for: %{email}'
leave_blank_if_you_don_t_want_to_change_it: leave blank if you don't want to change it leave_blank_if_you_don_t_want_to_change_it: Leave empty if you don't want to change it.
title: Edit %{resource} title: Edit my account
unhappy: Unhappy?
update: Update update: Update
we_need_your_current_password_to_confirm_your_changes: we need your current password to confirm your changes we_need_your_current_password_to_confirm_your_changes: We need your current password to confirm your changes
new: new:
sign_up: Sign up sign_up: Sign up
signed_up: Welcome! You have signed up successfully. signed_up: Welcome! You have signed up successfully.
@ -126,8 +126,8 @@ en:
sign_in_with_provider: Sign in with %{provider} sign_in_with_provider: Sign in with %{provider}
sign_up: Sign up sign_up: Sign up
minimum_password_length: minimum_password_length:
one: "(%{count} character minimum)" one: "%{count} character minimum."
other: "(%{count} characters minimum)" other: "%{count} characters minimum."
unlocks: unlocks:
new: new:
resend_unlock_instructions: Resend unlock instructions resend_unlock_instructions: Resend unlock instructions

View file

@ -93,14 +93,14 @@ es:
registrations: registrations:
destroyed: "¡Adiós! Tu cuenta ha sido cancelada correctamente. Esperamos verte pronto." destroyed: "¡Adiós! Tu cuenta ha sido cancelada correctamente. Esperamos verte pronto."
edit: edit:
are_you_sure: "¿Estás segura?" index: 'Volver a sitios'
cancel_my_account: Anular mi cuenta are_you_sure: "¿Estás segure?"
cancel_my_account: Eliminar mi cuenta
currently_waiting_confirmation_for_email: 'Actualmente esperando la confirmacion de: %{email} ' currently_waiting_confirmation_for_email: 'Actualmente esperando la confirmacion de: %{email} '
leave_blank_if_you_don_t_want_to_change_it: dejar en blanco si no desea cambiarlo leave_blank_if_you_don_t_want_to_change_it: Deja este campo vacío si no deseas cambiarla.
title: Editar %{resource} title: Editar mi cuenta
unhappy: "¿Disconforme?" update: Actualizar mi perfil
update: Actualizar we_need_your_current_password_to_confirm_your_changes: Necesitamos tu contraseña actual para confirmar los cambios.
we_need_your_current_password_to_confirm_your_changes: necesitamos tu contraseña actual para confirmar los cambios
new: new:
sign_up: Registrarme por primera vez sign_up: Registrarme por primera vez
email: O simplemente continuar con tu dirección de correo y contraseña email: O simplemente continuar con tu dirección de correo y contraseña
@ -110,7 +110,6 @@ es:
signed_up_but_unconfirmed: Para recibir actualizaciones, se ha enviado un mensaje con un enlace de confirmación a tu correo electrónico. Abre el enlace para activar tu cuenta. signed_up_but_unconfirmed: Para recibir actualizaciones, se ha enviado un mensaje con un enlace de confirmación a tu correo electrónico. Abre el enlace para activar tu cuenta.
update_needs_confirmation: Has actualizado tu cuenta correctamente, pero es necesario confirmar tu nuevo correo electrónico. Por favor, comprueba tu correo y sigue el enlace de confirmación para finalizar la comprobación del nuevo correo electrónico. update_needs_confirmation: Has actualizado tu cuenta correctamente, pero es necesario confirmar tu nuevo correo electrónico. Por favor, comprueba tu correo y sigue el enlace de confirmación para finalizar la comprobación del nuevo correo electrónico.
updated: Tu cuenta se ha actualizado. updated: Tu cuenta se ha actualizado.
updated_but_not_signed_in:
sessions: sessions:
already_signed_out: Sesión finalizada. already_signed_out: Sesión finalizada.
new: new:
@ -129,8 +128,8 @@ es:
i_dont_have_account: ¿Nunca te registraste en LUNAR? i_dont_have_account: ¿Nunca te registraste en LUNAR?
i_have_account: ¿Ya tenés cuenta? i_have_account: ¿Ya tenés cuenta?
minimum_password_length: minimum_password_length:
one: "(%{count} caracter como mínimo)" one: "%{count} caracter como mínimo."
other: "(%{count} caracteres como mínimo)" other: "%{count} caracteres como mínimo."
unlocks: unlocks:
new: new:
resend_unlock_instructions: Reenviar instrucciones para desbloquear resend_unlock_instructions: Reenviar instrucciones para desbloquear

View file

@ -1,4 +1,6 @@
en: en:
es: Castillian Spanish
en: English
seconds: '%{seconds} seconds' seconds: '%{seconds} seconds'
deploy_mailer: deploy_mailer:
deployed: deployed:
@ -29,6 +31,8 @@ en:
email: 'E-mail address' email: 'E-mail address'
password: 'Password' password: 'Password'
password_confirmation: 'Password confirmation' password_confirmation: 'Password confirmation'
current_password: 'Current password'
lang: 'Main language'
site: site:
name: 'Name' name: 'Name'
errors: errors:
@ -66,6 +70,8 @@ en:
posts: posts:
reorder: 'The articles have been reordered!' reorder: 'The articles have been reordered!'
help: help:
usuarie:
edit: Edit my profile
category: 'Category' category: 'Category'
logout: 'Close the session' logout: 'Close the session'
breadcrumbs: "What you see up here are the bread crumbs for this site. When you enter a new section, you will see the previous ones and also have a path for where you're standing." breadcrumbs: "What you see up here are the bread crumbs for this site. When you enter a new section, you will see the previous ones and also have a path for where you're standing."

View file

@ -1,4 +1,6 @@
es: es:
es: Castellano
en: Inglés
seconds: '%{seconds} segundos' seconds: '%{seconds} segundos'
deploy_mailer: deploy_mailer:
deployed: deployed:
@ -29,6 +31,8 @@ es:
email: 'Correo electrónico' email: 'Correo electrónico'
password: 'Contraseña' password: 'Contraseña'
password_confirmation: 'Confirmación de contraseña' password_confirmation: 'Confirmación de contraseña'
current_password: 'Contraseña actual'
lang: Idioma principal
site: site:
name: 'Nombre' name: 'Nombre'
title: 'Título' title: 'Título'
@ -68,6 +72,8 @@ es:
posts: posts:
reorder: "¡Los artículos fueron reordenados!" reorder: "¡Los artículos fueron reordenados!"
help: help:
usuarie:
edit: Editar mi perfil
category: 'Categoría' category: 'Categoría'
logout: 'Cierra la sesión' logout: 'Cierra la sesión'
breadcrumbs: 'Lo que ves arriba son las migas de pan de este sitio. breadcrumbs: 'Lo que ves arriba son las migas de pan de este sitio.

View file

@ -216,6 +216,7 @@ tengamos tiempo de hacerlo realmente.
# TODO # TODO
* aplicar la licencia al sitio!
* ver las estadisticas de compilación en lugar del log (el log también) * ver las estadisticas de compilación en lugar del log (el log también)
agrupar los build stats para poder ver todos los pasos de una agrupar los build stats para poder ver todos los pasos de una
@ -224,4 +225,3 @@ tengamos tiempo de hacerlo realmente.
* link a visitar sitio * link a visitar sitio
* editor de opciones * editor de opciones
* forkear gemas * forkear gemas
* que les usuaries elijan su propio idioma