开发者

How do I do substitutions for localised strings in freemarker

I'm using spring and freemarker and have the basics working.

I've got a properties file like

help.text=For further information please see the <a href="{0}">help page</a>.

I'm currently outputting localis开发者_如何转开发ed messages using

${rc.getMessage("help.text")}

However I'm having trouble figuring out how I can pass in my substitution variables. Can you help?

Cheers, Peter


If I read the Spring API documentation about RequestContext (your rc?) correctly, then

${rc.getMessage("help.txt", ["yourHelpUrl"])}

might work, because getMessage can receive an additional List argument with message args, which you can supply via a FreeMarker sequence.


<#import "/spring.ftl" as spring/>


<#assign args = ["yourHelpUrl"]>
<@spring.messageArgs "help.txt" args/>


I always do the substitution variables in my Java code somewhere and then dump the fully localized text into a Map where it's accessed by Freemarker like this:

${localizedValues["help.txt"]}


If you are correctly configuring freemarker in the spring MVC context then the right way to do it is:

  1. Import the spring macros in the template
  2. Use the mensaje macro

<#import "/spring.ftl" as spring />
<@spring.messageText "code", "Default message"/>

See the documentation: http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/view.html#view-velocity

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜