How to handle internationalization in a Spring application (inside a class)
I already know how to handle internationalization in Spring application using
JSP in page. Now my users are allowed to change languages using simple links like
Now I have to handle internationalization inside the class. This is what I did:
1) I created a text.xml file to determine where my texts are
..... <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basename" value="struttura"></property> </bean> ......
2) I created different properties files according to different languages
3) I am using this method to get the message according to the locale
...... ApplicationContext context = new ClassPathXmlApplicationContext("text.xml"); String stringa = context.getMessage("textCode",null, locale); .......
Everything is working. But I'm sure this isn't the fastest and cleanest way to do it. It looks too complicated!
Does anyone know the best way to achieve my goal?
source to share