Spring MVC Internationalization (i18n)

Internationalization is the process of developing software so that it can be easily adapted to different languages and regions without any code changes.

Core Components of Spring MVC i18n:

  • LocaleResolver: LocaleResolver is an interface that defines a strategy for resolving the current locale. It determines the locale to use from the HTTP request.
  • MessageSource: MessageSource is an interface in Spring that provides a way to resolve messages for a specific locale. It supports properties, XML, and YAML formats.
  • ViewResolvers: ViewResolvers determine how to render views based on the current locale. ContentNegotiatingViewResolver resolves the best matching view for a locale
  • LocaleChangeInterceptor: LocaleChangeInterceptor provides a mechanism for dynamic locale switching. It intercepts locale change requests and updates the locale in the request/session through the LocaleResolver.
  • Resource bundles: Properties files named messages_xx.properties containing localized text values for each locale.

Note: The MessageSource interface in Spring allows for internationalization support.

Spring MVC – Internationalization (i18n) and Localization (L10n)

Spring MVC is a Model-View-Controller (MVC) framework that is used to build web applications in Java. The Spring MVC pattern has three parts:

  • Model: The model contains the data that needs to be displayed on the view. A simple POJO class can be considered as a model.
  • View: The view is used for rendering the UI Operations.
  • Controller: The controller accepts user requests and passes them to the view for rendering.

Prerequisites of Topic

  • Java Development Kit (JDK) 11 or higher
  • Spring Boot 2.7.7 or higher
  • IDE of your choice (e.g., Eclipse, IntelliJ IDEA, STS(Spring Tool Suite))

Note: Here I’m Using STS as a IDE.

Similar Reads

Spring MVC Internationalization (i18n)

Internationalization is the process of developing software so that it can be easily adapted to different languages and regions without any code changes....

Localization (L10n) with Spring MVC

Spring MVC application must be localized to work in many languages and regions. This allows building applications that can be seamlessly localized for global users without code changes....

Example of Internationalization and Localization

Step 1: Spring MVC Project setup...