Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot Rest Multilanguage

I have an application, that uses Angular 2 for UI and Spring Boot Rest as a microservice. As a database, I have PostgreSQL. I want this project to support multi-languages. I heard that spring has something called i18n, but I don't know how to implement it.

One of my microservice is called categories, and what it does is CRUD operations. The default language is English, but I want to add french. So, if a call is like this: get: http://localhost:8080/categories?lang=fr I will get all the categories, where lang = 'fr'

Also, probably I will add a table called static_texts, where I will add words to translate, like: contact, menu, testimonials, etc. And for these words, when a user entered for the first time on site, angular will make a call to java to get all the static words, to save in a session, and to add those into the template.

Like this I see the multilanguage system, but, I don't understand how to implement it into my project. Do you have an example, because I couldn't find anything for what I need? Thanks!

like image 895
bogdan Avatar asked Jul 21 '17 13:07

bogdan


1 Answers

Spring Boot can manage any number of locales in an application flawlessly. Internationalization is a great way to increase users on a product so there are no limits in terms of how users use your product.

  1. The first and simple solution is to implement a LocaleResolver and LocaleChangeInterceptor for managing some resource files for different languages. you can see this tutorial. However, this approach depends on the access to the application’s resource files when adding a new supported language or modify the existing message files. In case an end-user is responsible for this job and obviously, this is not an optimal approach.
  2. Hence, the second method shows how to move all of our localized messages to a database. This enables the end-user to add a new language or update existing localized messages at runtime with the help of i18n. In this tutorial you'll see how to use your table for translated texts
like image 104
M-Razavi Avatar answered Sep 30 '22 11:09

M-Razavi