Spring boot thymeleaf cannot resolve arabic messages

Anass Ayar :

I am trying to create a Spring Boot 2.2.4 thymeleaf bilingual application (French and Arabic), here is the configuration I used, the problem is that when I switch to Arabic, I get this '?????? ?????'. I tried so many character encodings but nothing worked.

@Configuration
@EnableWebMvc
@ComponentScan
public class ThymeleafConfiguration implements WebMvcConfigurer {
    @Bean
    public SpringTemplateEngine templateEngine() {
        SpringTemplateEngine templateEngine = new SpringTemplateEngine();
        templateEngine.setTemplateResolver(thymeleafTemplateResolver());
        return templateEngine;
    }

    @Bean
    public SpringResourceTemplateResolver thymeleafTemplateResolver() {
        SpringResourceTemplateResolver templateResolver
                = new SpringResourceTemplateResolver();
        templateResolver.setPrefix("/WEB-INF/classes/templates/");
        templateResolver.setSuffix(".html");
        templateResolver.setTemplateMode("HTML5");
        templateResolver.setCharacterEncoding("UTF-8");
        templateResolver.setCacheable(false);

        return templateResolver;
    }

    @Bean
    public ViewResolver viewResolver(){
        ThymeleafViewResolver thymeleafViewResolver = new ThymeleafViewResolver();
        thymeleafViewResolver.setTemplateEngine(templateEngine());
        thymeleafViewResolver.setCharacterEncoding("UTF-8");
        return thymeleafViewResolver;
    }
}

EDIT : After closing and reopening the project, I noticed that arabic content in messages_ar.properties is converted to '???????? ????'

Anass Ayar :

When I noticed that the file is converted to unrecognized characters after each reopening of the project, I started to dig and I discovered that it was about file encoding, so I changed it and it worked.

https://blog.jetbrains.com/idea/2013/03/use-the-utf-8-luke-file-encodings-in-intellij-idea/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related