Spring local data

I have some problems setting up my web application to set the browser language of a remote user. For this, I used ResourceBundleMessageSource. It looks like this:

<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basename" value="resources/messages" /> </bean>

And I have two .properties files:

  • messages.properties

  • messages_ru.properties

They are located in src / resources / messages.

I want to configure such an application in such a way that when the language settings of the remote user’s browser contain Russian, my application should use Russian messages (messages_ru), otherwise (if the language is not configured or it is not Russian), it should use messages. properties (it contains English messages).

When I configure Russian in my browser, it works fine. When I erase all the settings, it also shows Russian (I think it depends on the system locale settings). And when I install some other language, it also shows me Russian messages.

The only way to make my application for displaying English messages is to rename messages.properties to messages_en.properties and set the English language in the browser. But I want to make my application accepted for all language settings (when it uses Russian, if necessary, and English for any other settings and any other countries).

Any ideas?

+3
source share
1 answer

You need to install

<bean id="messageSource" 
     class="org.springframework.context.support.ReloadableResourceBundleMessageSource">  
    <property name="basename" value="resources/messages" />
    <property name="fallbackToSystemLocale" value="false" />
</bean> 

Spring messages.properties , .

+5

Source: https://habr.com/ru/post/1776982/


All Articles