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: , , , , , .

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Recent Posts

Recent Comments

Categories

Top Posts

Links

Blog Stats

Meta