I18n - multiple templates per locale or multiple locale files
I'm working on redesigning a large consumer facing retail website. Think something like gap.com
开发者_如何学GoThe technology stack is Apache tiles, Apache velocity, Spring MVC.
Question: To implement I18N right, should I just create multiple velocity templates per locale or externalize strings into properties files? With the latter approach, there'll be much clutter in the velocity templates of the sort - resourcebundle.getMessage("website.title", "en_US") whereas in the earlier case, I'll probably have duplicated logic sitting in multiple templates.
You shouldn't do multiple templates (one per language). That would be counterproductive.
Also, you need to define some kind of wrapper for translating text. You don't want to use Locale or Locale Identifiers directly ("en_US"), instead you need to set Locale for the session and use this object (possibly implicitly, so you won't need to pass it every time you call getMessage()
, thus wrapper).
Be aware that if you call ResourceBundle
class' methods directly, some of may throw MissingResourceException
(which is runtime exception to make matter worse). You must be sure to check for it.
BTW. Velocity defines some tool for the localization purposes. Funny thing is, I never seen anybody actually using it (but to be honest my experience with Velocity is quite limited).
精彩评论