I'm translating an application based on REST using Spring Framework. Now I need to translate some responses based on the language of the request. For example:
/get-me-an-answer/?lang=es Spanish
/get-me-an-answer/?lang=en English
/get-me-an-answer/?lang=fr French
I have the variable language_code
as a static variable in a class named Translang
class Translang {
...
public static String language_code = null;
...
}
The problem is with multithreading, when a new request come will change the language and if another previous request is executing can probably answer in the language modified and not in the original language it requested.
That's the reason of my question: How can I have a global variable in Spring per request to avoid this problem?