mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-19 15:20:20 +00:00
terminado
This commit is contained in:
@ -22,15 +22,20 @@ public class InternationalizationConfig implements WebMvcConfigurer {
|
||||
@Bean
|
||||
public LocaleResolver localeResolver() {
|
||||
SessionLocaleResolver slr = new SessionLocaleResolver();
|
||||
slr.setDefaultLocale(Locale.of("es"));
|
||||
slr.setDefaultLocale(Locale.forLanguageTag("es")); // idioma por defecto
|
||||
return slr;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public LocaleChangeInterceptor localeChangeInterceptor() {
|
||||
LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
|
||||
lci.setParamName("lang"); // parámetro ?lang=en, ?lang=es
|
||||
return lci;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
LocaleChangeInterceptor interceptor = new LocaleChangeInterceptor();
|
||||
interceptor.setParamName("lang");
|
||||
registry.addInterceptor(interceptor);
|
||||
registry.addInterceptor(localeChangeInterceptor());
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ -40,22 +45,22 @@ public class InternationalizationConfig implements WebMvcConfigurer {
|
||||
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
|
||||
Resource[] resources = resolver.getResources("classpath*:i18n/*.properties");
|
||||
|
||||
// Extraer los nombres base sin extensión ni sufijos (_en, _es, etc.)
|
||||
// Extraer nombres base sin sufijos de idioma
|
||||
Set<String> basenames = Arrays.stream(resources)
|
||||
.map(res -> {
|
||||
try {
|
||||
String uri = Objects.requireNonNull(res.getURI()).toString();
|
||||
// Ej: file:/.../i18n/login_en.properties
|
||||
String path = uri.substring(uri.indexOf("/i18n/") + 1); // i18n/login_en.properties
|
||||
String base = path.replaceAll("_[a-z]{2}\\.properties$", "") // login.properties
|
||||
.replaceAll("\\.properties$", "");
|
||||
return "classpath:" + base;
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet());
|
||||
.map(res -> {
|
||||
try {
|
||||
String uri = Objects.requireNonNull(res.getURI()).toString();
|
||||
// Ejemplo: file:/.../i18n/login_en.properties
|
||||
String path = uri.substring(uri.indexOf("/i18n/") + 1); // i18n/login_en.properties
|
||||
String base = path.replaceAll("_[a-z]{2}\\.properties$", "") // login.properties
|
||||
.replaceAll("\\.properties$", "");
|
||||
return "classpath:" + base;
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
source.setBasenames(basenames.toArray(new String[0]));
|
||||
source.setDefaultEncoding("UTF-8");
|
||||
|
||||
Reference in New Issue
Block a user