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