如何制作语言(I18n)特定速度模板

发布于 2024-12-21 09:06:50 字数 424 浏览 3 评论 0原文

我想要特定于语言的速度模板。每个文件都应该位于自己的模板文件中(带有与普通资源文件相同的语言“后缀”)。

目前我正在使用:

String content = VelocityEngineUtils.mergeTemplateIntoString(this.velocityEngine, "newPasswordRequestDoubleOpt_locale.getLanguage().vm", 模型);

但随后我必须处理自己的问题,例如,如果当前语言没有模板,则回退到另一种语言......

所以我问 Velocity 中是否已经存在某种内置功能来处理这个完整的问题特定于语言的模板内容?或者有更好的方法吗?

用例:我使用 Velocity 生成电子邮件内容,其中大部分是一些文本,只有一些“变量”。)

I want to have language specific velocity template. Each one should be in its own template File (with an language "postfix" like the one used for normal resource files).

At the moment I am using:

String content = VelocityEngineUtils.mergeTemplateIntoString(this.velocityEngine,
"newPasswordRequestDoubleOpt_locale.getLanguage().vm",
model);

But then I have to deal my own with problem like, fall back to an other language if there is no template for the current one....

So I am asking is there already some kind of build in functionality in Velocity that handles this complete language specific template stuff? Or is there a better way?

(use case: I use Velocity to generate the Email content, most of it is some text, only some "variables".)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坏尐絯 2024-12-28 09:06:50

好吧,当您假设文本不是变量时,我认为您采取了错误的方法。

与任何其他模板一样,Velocity 的设计重点是结构,而不是内容。所以你的文本应该是你的变量的一部分。这样做,您可以受益于速度工具,例如 ResourceTool 允许您处理包含文本的 ResourceBundles。

Well, I think you're taking the wrong approach when you assume that your text is not a variable.

Velocity, like any other template is designed to focus structure, not content. So you text should be part of your variables. Doing so, you could benefit of the velocity tools, like the ResourceTool that allow you to deal with ResourceBundles that would contains your text.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文