Spring Boot Internationalization i18n
Spring Boot Internationalization i18n:
Rest Api sometimes need to write for different Language readers at that time internationalization is requiered (internationalization has 18 charecters so that by they use i18n)
We will be use of its a HTTP Request Header - Accept Language Header
- Accept-Language: indicate natural Language and local that the customer prefers
- Example: en - English (Good Morning)
- Example: nl - Dutch (Goedemorgen)
- Example: fr - French (Bonjour) etc
@RestController
public class HelloWorldController {
private MessageSource messageSource;
public HelloWorldController(MessageSource messageSource) {
this.messageSource = messageSource;
}
@GetMapping(path= "/hello-world-i18n")
public String helloWorldi18n() {
//this will provide which language is to pick as its pick from request header
Locale locale = LocaleContextHolder.getLocale();
String message = messageSource.getMessage("good.morning.message", null, "Defalt Message", locale);
return message;
}
}
Comments
Post a Comment