简体   繁体   English

使用Struts 2.x的自定义资源包/属性扩展库

[英]Use Custom Resource Bundle / Property Extension Library with Struts 2.x

Folks, 伙计们,

At present we use a set of standard properties files with Struts 2.x to provide our I18N functionality - and for the most part, these do exactly what we need them to. 目前,我们使用一组带有Struts 2.x的标准属性文件来提供我们的I18N功能 - 在大多数情况下,这些文件正是我们所需要的。 However, there are occasions when it would be great to be able to have individual properties reference other properties in the resource bundle, for example: 但是,有时候能够让各个属性引用资源包中的其他属性会很棒,例如:

name.first=John
name.last=Doe
name.full={name.first} {name.last}

I am aware of several extensions to java.util.Properties that provide these sorts of capabilities such as: 我知道java.util.Properties的几个扩展,提供了这些类型的功能,例如:

I was wondering if anyone has ever attempted to integrate these somehow into Struts 2.x - is it possible to override the mechanism which handles the parsing of resource bundles? 我想知道是否有人试图将这些以某种方式集成到Struts 2.x中 - 是否有可能覆盖处理资源包解析的机制?

There's nothing like this built-in, but IIRC you can set a text provider via: 没有像内置的那样,但是IIRC你可以通过以下方式设置文本提供者:

<bean type="com.opensymphony.xwork2.TextProvider" name="struts"
     class="com.opensymphony.xwork2.TextProviderSupport" scope="default" />

I've never actually done this, but it's a worthy, interesting experiment. 我从来没有真正做到这一点,但这是一个值得的,有趣的实验。

Properties may include arbitrary OGNL, however–you can fake it (verbosely) in the meantime: 属性可能包含任意OGNL,但是你可以在此期间伪造它(冗长地):

name.first=John
name.last=Doe
name.full=%{getText('name.first')} %{getText('name.last')}

(You may also use ${...}, but I prefer %{...} so it's clear it's OGNL.) (你也可以使用$ {...},但我更喜欢%{...}所以很明显它是OGNL。)

I've bookmarked this question for research, there are several cool ideas here. 我已将这个问题加入书签进行研究,这里有几个很酷的想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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