Wednesday, April 29, 2015

How to handle localized resources with resource bundle

Generally, there are 2 ways to handle localized resources.
1. Append the locale name to the end of the file name. eg, logo_en_US.jpg, flag_zh_CN.png
2. Save the resources of the locale to individual resource bundle.

Solution 1 is kind of straight forward,
thus, in this post, we will be focusing on Solution 2. 

Normally, in java development, we have different resource bundle to handle localized messages, labels for different locales. 
eg, system-messages_en_US.properties, system-messages_ms_MY.properties, etc

Steps
1. define the resource key, eg. jquery.validation.path
2. define the value of the key based on different locale.

messages_zh_CN.properties
jquery.validation.path=https://github.com/jzaefferer/jquery-validation/blob/master/src/localization/messages_zh.js

messages_fr.properties
jquery.validation.path=https://github.com/jzaefferer/jquery-validation/blob/master/src/localization/messages_fr.js

3. use the bundle key to retrieve value for the resource path.

<script src="#{msg['jquery.validation.path']}" type="text/javascript">



Done!!

LinkWithin

Related Posts Plugin for WordPress, Blogger...