开发者

Adding i18n support after the fact

I apologise in advance if this is a bit of a subjective/discussion type question. What I would like to have are good ways to retrofit locale information to a web application that is primarily JSP. The framework is... well non existent, just lots of .jsp pages with tons of scripting and JavaScript twiddling. I just started, so I'm not yet in any position to suggest an overhaul, although I think i'll get around to that at some point.

Now, someone on the team has suggested some "easy" javascript based content localization using browser locale or somesuch. This is setting off all kinds of alarms in my head.

But what would be a good way to use Java Locale support via JSP pages, that would then be easy to extend to a nice framework like JSF 2?

This is what I was thinking:

  • Move al开发者_JAVA百科l possible display strings to *_locale.properties files
  • Build a utility class that reads from proper file based on locale info in request/session
  • Embed said utility class in all jsp files
  • Replace all <title>Page 1</title> into <title>localeUtils.getString("page1.title)</title>

Suggestions?


If you're not able to move to a framework right away that supports localization out of the box (Spring comes to mind here), then you'll have to come up with your own solution and the one you have provided seems like a good start. Definitely use property files to store your locale-specific strings and use the supported Java locale IDs in the name of each locale-specific property file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜