From 54798b755499d19bb7168d6b93882969d887cc09 Mon Sep 17 00:00:00 2001 From: Pablo de la Torre Jamardo Date: Mon, 15 Sep 2025 08:24:28 +0200 Subject: [PATCH] feat(i18n): add English, Spanish and Galician translations for error messages --- .../infrastructure/config/LocaleConfig.java | 25 +++++++++++++++++ .../infrastructure/config/MessageConfig.java | 27 +++++++++++++++++++ .../main/resources/i18n/messages.properties | 9 +++++++ .../resources/i18n/messages_es.properties | 9 +++++++ .../resources/i18n/messages_gl.properties | 9 +++++++ 5 files changed, 79 insertions(+) create mode 100644 infrastructure/src/main/java/com/pablotj/restemailbridge/infrastructure/config/LocaleConfig.java create mode 100644 infrastructure/src/main/java/com/pablotj/restemailbridge/infrastructure/config/MessageConfig.java create mode 100644 infrastructure/src/main/resources/i18n/messages.properties create mode 100644 infrastructure/src/main/resources/i18n/messages_es.properties create mode 100644 infrastructure/src/main/resources/i18n/messages_gl.properties diff --git a/infrastructure/src/main/java/com/pablotj/restemailbridge/infrastructure/config/LocaleConfig.java b/infrastructure/src/main/java/com/pablotj/restemailbridge/infrastructure/config/LocaleConfig.java new file mode 100644 index 0000000..0bea91f --- /dev/null +++ b/infrastructure/src/main/java/com/pablotj/restemailbridge/infrastructure/config/LocaleConfig.java @@ -0,0 +1,25 @@ +package com.pablotj.restemailbridge.infrastructure.config; + +import java.util.List; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.LocaleResolver; +import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver; + +import java.util.Locale; + +@Configuration +public class LocaleConfig { + + @Bean + public LocaleResolver localeResolver() { + AcceptHeaderLocaleResolver resolver = new AcceptHeaderLocaleResolver(); + resolver.setDefaultLocale(Locale.of("en")); + resolver.setSupportedLocales( + List.of(Locale.of("es"), + Locale.of("en"), + Locale.of("gl")) + ); + return resolver; + } +} diff --git a/infrastructure/src/main/java/com/pablotj/restemailbridge/infrastructure/config/MessageConfig.java b/infrastructure/src/main/java/com/pablotj/restemailbridge/infrastructure/config/MessageConfig.java new file mode 100644 index 0000000..a49bf3b --- /dev/null +++ b/infrastructure/src/main/java/com/pablotj/restemailbridge/infrastructure/config/MessageConfig.java @@ -0,0 +1,27 @@ +package com.pablotj.restemailbridge.infrastructure.config; + +import org.springframework.context.MessageSource; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.support.ResourceBundleMessageSource; +import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; + +@Configuration +public class MessageConfig { + + @Bean + public MessageSource messageSource() { + ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); + messageSource.setBasename("i18n/messages"); + messageSource.setDefaultEncoding("UTF-8"); + messageSource.setUseCodeAsDefaultMessage(false); + return messageSource; + } + + @Bean + public LocalValidatorFactoryBean validator(MessageSource messageSource) { + LocalValidatorFactoryBean bean = new LocalValidatorFactoryBean(); + bean.setValidationMessageSource(messageSource); + return bean; + } +} \ No newline at end of file diff --git a/infrastructure/src/main/resources/i18n/messages.properties b/infrastructure/src/main/resources/i18n/messages.properties new file mode 100644 index 0000000..ccf8050 --- /dev/null +++ b/infrastructure/src/main/resources/i18n/messages.properties @@ -0,0 +1,9 @@ +email.from.invalid=Sender email must be valid +email.from.blank=Sender email cannot be blank +email.from.length=Sender email must be between 4 and 100 characters + +email.subject.blank=Subject cannot be blank +email.subject.length=Subject must be between 1 and 30 characters + +email.body.blank=Body cannot be blank +email.body.length=Body must be between 1 and 4000 characters \ No newline at end of file diff --git a/infrastructure/src/main/resources/i18n/messages_es.properties b/infrastructure/src/main/resources/i18n/messages_es.properties new file mode 100644 index 0000000..c2d136f --- /dev/null +++ b/infrastructure/src/main/resources/i18n/messages_es.properties @@ -0,0 +1,9 @@ +email.from.invalid=El remitente debe ser un correo válido +email.from.blank=El remitente no puede estar vacío +email.from.length=El remitente debe tener entre 4 y 100 caracteres + +email.subject.blank=El asunto no puede estar vacío +email.subject.length=El asunto debe tener entre 1 y 30 caracteres + +email.body.blank=El cuerpo no puede estar vacío +email.body.length=El cuerpo debe tener entre 1 y 4000 caracteres \ No newline at end of file diff --git a/infrastructure/src/main/resources/i18n/messages_gl.properties b/infrastructure/src/main/resources/i18n/messages_gl.properties new file mode 100644 index 0000000..50294bf --- /dev/null +++ b/infrastructure/src/main/resources/i18n/messages_gl.properties @@ -0,0 +1,9 @@ +email.from.invalid=O remitente debe ser un correo válido +email.from.blank=O remitente non pode estar baleiro +email.from.length=O remitente debe ter entre 4 e 100 caracteres + +email.subject.blank=O asunto non pode estar baleiro +email.subject.length=O asunto debe ter entre 1 e 30 caracteres + +email.body.blank=O corpo non pode estar baleiro +email.body.length=O corpo debe ter entre 1 e 4000 caracteres \ No newline at end of file