diff --git a/Gemfile b/Gemfile index 96ffa02..b97d456 100644 --- a/Gemfile +++ b/Gemfile @@ -45,7 +45,7 @@ gem 'commonmarker' gem 'devise' gem 'devise-i18n' gem 'devise_invitable' -gem 'email_address' +gem 'email_address', git: 'https://github.com/fauno/email_address', branch: 'i18n' gem 'exception_notification' gem 'fast_blank' gem 'friendly_id' diff --git a/Gemfile.lock b/Gemfile.lock index 8d4da43..befd414 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -6,6 +6,15 @@ GIT rails (>= 3.0) rake (>= 0.8.7) +GIT + remote: https://github.com/fauno/email_address + revision: 536b51f7071b68a55140c0c1726b4cd401d1c04d + branch: i18n + specs: + email_address (0.1.20) + netaddr (>= 2.0.4, < 3) + simpleidn + GEM remote: https://rubygems.org/ remote: https://gems.sutty.nl/ @@ -163,9 +172,6 @@ GEM em-websocket (0.5.2) eventmachine (>= 0.12.9) http_parser.rb (~> 0.6.0) - email_address (0.1.19) - netaddr (>= 2.0.4, < 3) - simpleidn errbase (0.2.1) erubi (1.10.0) eventmachine (1.2.7) @@ -595,7 +601,7 @@ DEPENDENCIES dotenv-rails down editorial-autogestiva-jekyll-theme - email_address + email_address! exception_notification factory_bot_rails fast_blank diff --git a/app/models/usuarie.rb b/app/models/usuarie.rb index 0aa41ee..6de7ba4 100644 --- a/app/models/usuarie.rb +++ b/app/models/usuarie.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require 'open-uri' - # Usuarie de la plataforma class Usuarie < ApplicationRecord devise :invitable, :database_authenticatable, @@ -9,6 +7,7 @@ class Usuarie < ApplicationRecord :confirmable, :lockable, :registerable validates_uniqueness_of :email + validates_with EmailAddress::ActiveRecordValidator, field: :email has_many :roles has_many :sites, through: :roles diff --git a/config/application.rb b/config/application.rb index ef82167..c7afe9d 100644 --- a/config/application.rb +++ b/config/application.rb @@ -37,5 +37,15 @@ module Sutty .rescue_responses['Pundit::NotAuthorizedError'] = :forbidden config.active_storage.variant_processor = :vips + + config.after_initialize do + I18n.available_locales.each do |locale| + translations = I18n.t(:email_address, locale: locale) + + next unless translations.is_a? Hash + + EmailAddress::Config.error_messages translations.transform_keys(&:to_s), locale.to_s + end + end end end diff --git a/config/locales/en.yml b/config/locales/en.yml index c66697e..4a84301 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -604,3 +604,23 @@ en: url: Address more: More heading levels word: "If you're pasting from an hegemonic word processor, please be patient with us, it's not always simple to recover the whole format :)" + email_address: + address_unknown: "the address is unknown" + domain_does_not_accept_email: "this domain is not configured to accept email" + domain_invalid: "domain name format is incorrect" + domain_no_localhost: "localhost is not allowed for your domain name" + domain_unknown: "domain name not registered" + exceeds_size: "address is too long" + incomplete_domain: "domain name is incomplete (ie: missing .com)" + invalid_address: "format is incorrect (ie: user@example.org)" + invalid_host: "provider format is incorrect" + invalid_mailbox: "the account format is incorrect (ie: contains spaces)" + ip_address_forbidden: "IP addresses are not allowed" + ip_address_no_localhost: "localhost IP addresses are not allowed" + ipv4_address_invalid: "the address is not a valid IPv4 address" + ipv6_address_invalid: "the address is not a valid IPv6 address" + local_size_long: "the account name is too long" + local_size_short: "the account name is too short" + local_invalid: "format is incorrect" + not_allowed: "is not welcome here" + server_not_available: "the remote email server is not available" diff --git a/config/locales/es.yml b/config/locales/es.yml index 637a8f9..62c3f8e 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -617,3 +617,23 @@ es: url: Dirección more: Más niveles de título word: "Si estás pegando texto desde un hegemónico editor de texto que empieza con W, por favor tenenos paciencia, no siempre es simple recuperar y respetar todo el formato :)" + email_address: + address_unknown: "la dirección es desconocida" + domain_does_not_accept_email: "el nombre de dominio no acepta correo" + domain_invalid: "el nombre de dominio no es válido" + domain_no_localhost: "no se permiten direcciones locales" + domain_unknown: "el nombre de dominio no existe" + exceeds_size: "la dirección es demasiado larga" + incomplete_domain: "el nombre de dominio está incompleto (ej. ¿falta el .com?)" + invalid_address: "la dirección no tiene el formato correcto (ej. usuarie@dominio.org)" + invalid_host: "el nombre de dominio es incorrecto" + invalid_mailbox: "el nombre de la cuenta es incorrecto (ej. tiene espacios)" + ip_address_forbidden: "no se permiten direcciones IP" + ip_address_no_localhost: "no se permiten direcciones IP locales" + ipv4_address_invalid: "no es una dirección IPv4 válida" + ipv6_address_invalid: "no es una dirección IPv6 válida" + local_size_long: "el nombre de la cuenta es muy largo" + local_size_short: "el nombre de la cuenta es muy corto" + local_invalid: "el formato es incorrecto" + not_allowed: "no es bienvenida" + server_not_available: "el proveedor no está disponible"