Setting up and using Resource bundles in ColdBox
Tags: Coldfusion, ColdFusion 8, ColdFusion 9, Coldbox
I was asked the other day for some examples on using resource bundles inside ColdBox, and even though it is rather easy to use and setup, I thought I would do a very quick post on how easy it is.
The very first thing that one needs to do is the configuration, and is as simple as placing the following inside the ColdBox configuration file.
<DefaultResourceBundle>i18n/messages</DefaultResourceBundle>
<DefaultLocale>en_US</DefaultLocale>
<LocaleStorage>session</LocaleStorage>
<UknownTranslation></UknownTranslation>
</i18N>
These settings are very straight forward and tell us where to find the resources, what is going to be the default resource and whether this is going to be session or client loaded. For more information on this pleas check out the ColdBox wiki for more detailed information.
http://wiki.coldbox.org/wiki/Plugins:i18n.cfm
So how doe we use this, well very simply we would just use something like this in our code
Which says to us that we are wanting to load the local for the default locale, if we didn't use the setfwLocale, then it would default to the setting that we defaulted it too.
What this then does is look for a file as in our settings defined, for a file called messages_en_US.properties, which would have the following type of information inside the file.
category=Category
categoryeditor=Category Editor
categorystats=Category Stats
commentadded=Comment added
commentaddedtoblog=Comment added to Blog
commentaddedtoblogentry=Comment added to Blog Entry
commentmadeby=Comment made by
Which is basically a key and value definition, which we can then use in our application like this.
Which would then get the text assigned to this key. That is pretty much how easy it is to use, but there is a lot more to the resource bundle than what I have shown here, and it would be highly advisable to read the wiki over at the previous link above.
There are no comments for this entry.



TweetBacks