Sunday, August 17, 2008

Old-School i18n

In order to get a better understanding of the current/traditional Spring i18n technique I implemented it in my ELEC5619 tutorial application.

The application already had a messagesource in the form of
<bean id="messageSource" class="">
<property name="basenames">

I had to declare an interceptor and then a resolver.

<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="siteLanguage">

<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver"></bean></bean>

and add the interceptor to the urlMapping

The project already had so I added a new localised message-set for French as

Then add the spring taglib to include.jsp
<%@ taglib prefix="spring" uri="/WEB-INF/spring.tld" %>

and finally update the jsp so use the spring taglib instead of jstl. So for example
<spring:message code="title"></spring:message>

Changing the language setting inside the browser to French resulted in the output being localised for Fr_fr -> SUCCESS!

Now I need to move forward onto a translation interface, however I'm seeing a few complications as I'm not sure how to go about a few things. Namely, I need to be able to add links of some form to all the message.keys in translator mode. When translator mode is enabled the controller could redirect to a different jsp and manually add a traditional link for each message.key but this is going to result in a lot of tedious re-coding. I'm hoping to just be able to render the jsp and add the link somehow without requiring a different jsp for when translator is enabled.

The other issue I need to consider is how to interface to simply localise any text pulled from a database.

No comments: