Nothing special. just bits and pieces about my life, my career and my loves.

Thursday, November 15, 2007

Here I come !!!

With the release of its SDK yesterday, Android, Google's new open source mobile operating system, has announced a developer challenge with $10 million in awards.

The 50 most promising mobile apps built for the platform will each receive $25,000 award to fund further development. Those selected will then be eligible for even greater recognition via ten $275,000 awards and ten $100,000 awards.

http://code.google.com/android/adc.html

I wish I can come up some idea over this weekend



Thursday, November 08, 2007

Java/Spring i18n



My manager asked me to create a Japanese version of Michael Page Mobile Website few days ago, I thought it would be fairly straight forward as I already defined all the texts in a properties file. I guessed all I need to do is just created a message_ja_JP.properties file and find out a way how to set the locale for the JSTL fmt:message tag.

Of course, It ended up to be much more complicated than I expected. Hence I decide to blog what I had done for further references.

  1. open message.properties in a MS Word. Covert all the values in japanese and then save the file as message_ja_JP.txt, make sure to encode the file to unicode format.
  2. execute $JAVA_HOME/bin/native2ascii -encoding UnicodeLittle message_ja_JP.txt message_ja_JP.properties. Open message_ja_JP.properties with MS-Word with UTF-8 encoding. You will notice that all the text is covert to something like keyName=\u826f\u3092\u696d\u754c
  3. Defined a bean named "localeResolver" in the spring web application context, this mean must implement org.springframework.web.servlet.LocaleResolver interface. Basically, jstl will use this resolver to resolve the locale.
  4. Added <%@ page pageEncoding="UTF-8" %> at the top of every single JSPs and <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" /> between the html head tag.
  5. Create a Servlet Filter and put it the end of the filter chain.
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { request.setCharacterEncoding("charset=UTF-8"); response.setContentType("UTF-8"); chain.doFilter(request, response); }
  6. This filter must put after Sitemesh filter (if applicable)
  7. Use org.springframework.mail.javamail.MimeMessagePreparator and org.springframework.mail.javamail.JavaMailSender instead of SimpleMessage and MailSender, this allows you to encode the character to UTF-8 format.
  8. IF you use DisplayTag for paging, you need to add locale.resolver=org.displaytag.localization.I18nSpringAdapter in the displaytag.properties file and then create displaytag_ja_JP.properties for Japanese messages.
  9. Use org.springframework.context.MessageSource if you need to lookup localized message in the service layer, by injectMessageSource instance (e.g. org.springframework.context.support.ResourceBundleMessageSource) to your service class.
You should now able to display the proper message :)
I also found this link very useful.