Unsupported characters for the charset 'ISO-8859-1' in Spring Res file
Asked Answered
O

2

5

I am trying to implement localization in my spring boot project. And it fine work in some language like Locale.ITALIAN ,Locale.GERMAN. In case of

Malayalam , Tamil and Hindi

getting "???" in api response. Here I am sharing my code and screen shots

Application class

@SpringBootApplication
public class JavaI18nSpringBootApplication implements WebMvcConfigurer {

    public static void main(String[] args) {
        SpringApplication.run(JavaI18nSpringBootApplication.class, args);

    }

    @Bean
    public CharacterEncodingFilter characterEncodingFilter() {
        final CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
        characterEncodingFilter.setEncoding("UTF-8");
        characterEncodingFilter.setForceEncoding(true);
        return characterEncodingFilter;
    }
}

Controller

public class HelloController {

@Autowired
private LocaleResolver localeResolver;

@Autowired
Messages messages;

@Autowired
private HttpServletRequest httpServletRequest;
@Autowired
private HttpServletResponse httpServletResponse;
@GetMapping("/test")
@ResponseBody
public String test() {
    return  messages.get("hello");

}

Message class

    @Component
public class Messages {
    @Autowired
    private MessageSource messageSource;

    private MessageSourceAccessor accessor;

    @PostConstruct
    private void init() {
        Locale l = new Locale("ml", "IN");
        accessor = new MessageSourceAccessor(messageSource, l);
    }

    public String get(String code) {
        return accessor.getMessage(code);
    }

}

application.properties

Onehorse answered 1/11, 2021 at 8:13 Comment(3)
I think you should change the file-encoding to fix this. The file encoding of the application.properties.Primeval
@AbuBakarKhan already tried that input.encoding=utf-8 output.encoding=utf-8Onehorse
no i mean the properties file itselfPrimeval
G
9

if first answer didnt helped with showing messages

In intellij idea go to: File->Settings->Editor->File Encoding and mark transparent native
enter image description here

Gregorygregrory answered 20/8, 2022 at 7:50 Comment(0)
R
3

In intellij idea go to: File->Settings->Editor->File Encoding, and change 'default encoding for properties files' to UTF-8

Responser answered 4/3, 2022 at 6:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.