Use a different template for a given Locale

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Use a different template for a given Locale

Laurent
Hi,

I'm working on a web application using thymeleaf and spring 3 so I have a ITemplateResolver and a MessageSource injected in a SpringTemplateEngine.

For most of the i18n stuff using #{} fit my need perfectly but for some languages the template needs to be very different from the other languages (while the data in it are pretty much the same).

So I was wondering if there was a way to have localized templates like this:
my-template.html <- this is the default one
my-template_en_GB.html <- this template is used only if the context Locale is en_GB

As far as I know the ITemplateResolver should be able to get the Locale from the IProcessingContext in the TemplateProcessingParameters given when calling ITemplateResolver.resolveTemplate().

The major drawback I see here is that I'm going to loose cache capability has the cache key if the raw template name.

Does anyone know if I going the right way (by implementing my own resolver) or if I'm loosing my time? ;-)

Thanks for any insights,

Laurent.
Reply | Threaded
Open this post in threaded view
|

Re: Use a different template for a given Locale

Emanuel
Administrator
I'm not too familiar with the template resolution mechanism when it comes to locales, but what I think you're aiming to do is right, knowing how locale resolution works for other things like properties files.  I mean, it's what I'd expect the template resolver to do if it was locale-sensitive.