我有一个 spring boot 应用程序,我使用两种语言英语和法语。我有我的文件 messages.fr 和 messages.en 作为参考,可以在 thymeleaf 的帮助下更改 html 文档中的语言。
我的重音内容看起来像这样的问题:例如“Cr?er un compte”(创建一个帐户)它应该是:“Créer un compte”
在 Spring Boot 中完成此操作的最佳方法是什么?感谢您的帮助..
请记住,我的属性中有这个百里香配置
# INTERNATIONALIZATION (MessageSourceProperties)
spring.messages.always-use-message-format=false
spring.messages.basename=messages
spring.messages.cache-duration=-1
spring.messages.encoding=UTF-8
spring.messages.fallback-to-system-locale=true
#Thymeleaf configurations
spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.cache=false
spring.thymeleaf.check-template=true
spring.thymeleaf.check-template-location=true
spring.thymeleaf.content-type=text/html
spring.thymeleaf.enabled=true
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.suffix=.html
spring.thymeleaf.prefix=classpath:/templates/
Run Code Online (Sandbox Code Playgroud)
我在我的配置中使用这些 bean
@Bean
public LocaleChangeInterceptor localeChangeInterceptor() {
LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor();
LocaleChangeInterceptor.setParamName("lang");
return localeChangeInterceptor;
}
@Bean
public LocaleResolver localeResolver() {
final CookieLocaleResolver cookieLocaleResolver = new CookieLocaleResolver();
cookieLocaleResolver.setDefaultLocale(Locale.ENGLISH);
return cookieLocaleResolver;
}
public void addInterceptors(InterceptorRegistry registry){
registry.addInterceptor(localeChangeInterceptor());
}
Run Code Online (Sandbox Code Playgroud)
我运行此代码来测试内容类型
@RequestMapping(value …Run Code Online (Sandbox Code Playgroud)