Szocske
Szocske

Reputation: 7661

Spring MVC with FreeMarker: locale specific templates

We are prototyping an otherwise simple Spring MVC application with a single twist: We'll have separate FreeMarker template files for the different locales. So for the view "homepage" with locale US English, the viewresolver should find the template file homepage_en_us.ftl Failing that, homepage_en.ftl, failing that homepage.ftl Just like property files.

I know it's better to have one template with messages, but the template files are exposed to users who are more comfortable copy-pasting than the resource abstraction, and they may have to make actual layout changes for the different locales.

What's the most Springy way to achieve this?

Upvotes: 0

Views: 1778

Answers (1)

FauxFaux
FauxFaux

Reputation: 2515

This is the default behaviour?

I have my view resolver defined like:

<bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
    <property name="cache" value="true" />
    <property name="prefix" value="/ftl/" />
    <property name="suffix" value=".ftl" />
    <property name="exposeSpringMacroHelpers" value="true" />
    <property name="exposeRequestAttributes" value="true" />
    <property name="exposeSessionAttributes" value="true" />
</bean>

... and it will, when asked for a view of foo, pick foo_en.ftl over foo.ftl?

If you're using a custom view resolver, you might want to get it to use org.springframework.web.servlet.viewAbstractTemplateViewResolver so you get all the cool behaviour for free?

Upvotes: 1

Related Questions