简体   繁体   中英

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?

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM