是否可以从速度模板中的属性文件中动态读取静态文本? [英] Is it possible to read static text dynamically from property files in velocity template?

查看:224
本文介绍了是否可以从速度模板中的属性文件中动态读取静态文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候所有
i有一个java ee应用程序(spring框架),它使用vm模板
,其中包含静态文本,如:

greetings all i have a java ee application (spring framework) that uses vm templates that contains static texts like:

<span> hello world </span>

类似于:

<span> <fmt:message key="hi.message" /> </span>

我想知道是否可以从属性文件(en / fr)读取文本在JSP中的用户区域设置上,因此我将为所有区域设置使用一个模板,文本是动态的

and i was wondering if it's possible to read that texts from a property file(en/fr) depending on the user locale like in JSP, so that i will use one template for all locales and the text is dynamic

注意:velocity不是我在应用程序中使用的视图技术,我只在发送电子邮件时使用它的模板。

Note: velocity is not my view technology used in the app, i am using it's templates in sending emails only.

推荐答案

我们不能在网络应用程序之外使用宏,就像我的情况一样一个解决方案是使用messageSource

We cannot use macros outside the web app, like in my case so a solution would be to use messageSource

model.put("messagesource", this.messagesource);
// adding this e.g. should do the trick
model.put("keyHelloCustomer", "the_key_you_use_in_your_properties_file");
model.put("noArgs", new Object[]{});
model.put("locale", yourOwnPrivateMethodToDetermineWhichLocaleToUse()); 

和vm:

${messageSource.getMessage($keyHelloCustomer, $noArgs, $locale)}

参考:
http://forum.springsource.org/showthread。 php?t = 82018

这篇关于是否可以从速度模板中的属性文件中动态读取静态文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆