Using i18n in the Spring Controllers
July 4, 2008
Context :
This article, in brief, highlights the steps required to make use of i18n (internationalisation) within the controllers (or any other *.java files, for that matter) for an application making use of the spring framework.
Guidelines :
Step 1 : To load the xml file containing the the resource bundle configuraitons, from the class path.
Locale locale = RequestContextUtils.getLocale(req); ApplicationContext ctx = new ClassPathXmlApplicationContext( "../foo-context.xml" )
Step 2 : To load the appropriate message value provided with the relevant key
ctx.getMessage( "fooKey", null, locale );
Additionally…
Step 3 : To check the current locale
if( locale.equals( Locale.ENGLISH ) ) ...
… Wa Allahu A’lam
Entry Filed under: Java, Spring. Tags: Spring + i18n, Spring framework i18n, spring framework utf8, spring internationalisation + controllers, spring utf8, Using i18n in the Spring Controllers.
Trackback this post | Subscribe to the comments via RSS Feed