How to generate "lang" parameter at the end of the url without making a request in each controller in Spring?

449 views Asked by At

I want to add internationalization support to Spring project that I'm working on. It works when I add "lang" parameter at the end of the url like;

localhost:8080/someurl?lang=en

However, I can not generate the parameter at the end of the url, I need to make a parameter request from the controller.

I don't think it is a good idea to request lang parameter in each controller. I believe there is a better way to implement but I don't know what it is.

Do you have any suggestion where should I look for it?

Edit: I have a langKey field for the entity User so, I want to generate lang parameter by using the field langKey of the User.

1

There are 1 answers

0
Atilla On

I realized that applying the lang parameter only once is sufficient for the rest of the session so, there is no need to add lang parameter in each controller. It was enough for me to only add the lang parameter for the redirection after login according to users langKey. Then the rest of the session displayed according to language choice of the user stored in database.

I hope that helps for the others.