users@jersey.java.net

Re: [Jersey] I18N for Jersey's MVC/templating support.

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 03 Apr 2009 15:56:37 +0200

On Apr 2, 2009, at 10:39 PM, Casper Bang wrote:

> Thanks guys, the filter idea is not bad except it's a real mess
> pulling {language} out from the UriInfo.

Can you explain what is messy, i might be able to help clean it up a
little.

You can use UriTemplate to match with a template:

https://jersey.dev.java.net/source/browse/*checkout*/jersey/tags/jersey-1.0.2/api/jersey/com/sun/jersey/api/uri/UriTemplate.html

Ot it might be better to use a resource specific filter factory instead:

   https://jersey.dev.java.net/source/browse/*checkout*/jersey/tags/jersey-1.0.2/api/jersey/com/sun/jersey/api/container/filter/package-summary.html

   https://jersey.dev.java.net/source/browse/*checkout*/jersey/tags/jersey-1.0.2/api/jersey/com/sun/jersey/spi/container/ResourceFilterFactory.html

and extract out the language value from the
HttpContext.getUriInfo().getPathParameters().getFirst("language")




> Realizing I'm already sitting on this fantastic JSON delivery engine
> though, I'm using simple markup:
>
> <h1 class="i18n" id="apptitle"></h1>
>
> ...along with a jquery script that downloads a "dynamic" JavaScript,
> which is a key:value map, used to index into with the id (apptitle
> in the above). It has the potential of allowing dynamic language
> change without a page refresh, as well as allowing translators to
> update resources on-the-fly and without a re-deploy.
>
> It seems to work, though still needs some polishing (bridge to
> ResorceBundle etc.). But I have to say, it's a little fun to witness
> how my, at first, static REST application is turning out to be
> delivering a so much more dynamic experience than any other web
> application I've ever worked on.
>

Great!

Paul.