Fid*_*Fid 7 java translation servlets internationalization
我有这样的枚举
public enum CheckboxFeature {
Option1(" choose this"),
Option2(" or this"),
Option3(" maybe this"),
Option4(" lastly this");
@Getter
private final String text;
public static CheckboxFeature fromName(String v) {
for (CheckboxFeature c: CheckboxFeature.values()) {
if (c.name().equalsIgnoreCase(v)) {
return c;
}
}
throw new IllegalArgumentException(v);
}
}
Run Code Online (Sandbox Code Playgroud)
这会在Web视图中显示四个选项作为复选框
<form:checkboxes items="${features}" path="enabledFeatures" itemLabel="text" delimiter="<br/>"/>
Run Code Online (Sandbox Code Playgroud)
我该如何翻译这些选项?我对Web视图中的其余翻译使用fmt:message.
我试过了
Option1(" <fmt:message key=\"text.test\"/>"),
Run Code Online (Sandbox Code Playgroud)
和
Option1(" ${option1}"),
Run Code Online (Sandbox Code Playgroud)
同
<fmt:message key="text.select" var="option1"/>
Run Code Online (Sandbox Code Playgroud)
在.jsp中.它们都不起作用,所以它似乎无法以这种方式工作.翻译字符串的正确方法是什么?理想情况下使用fmt:message和i18n资源(lang.properties文件)到位并处理其余的servlet?
最理想的是,您从枚举中获取资源键,并查看它.
public enum CheckboxFeature {
Option1("label.option1.key"),
Option2("label.option2.key"),
Option1("label.option3.key"),
Option2("label.option4.key");
private final String key;
[...]
Run Code Online (Sandbox Code Playgroud)
我不知道如何在itemLabel属性中嵌套l10n查找,所以我会写如下:
<c:forEach items="Options.values()" var="current">
<form:checkbox path="selectedOptions" value="${current.name()}"/> <fmt:message key="${current.getKey()}"/>
</c:forEach>
Run Code Online (Sandbox Code Playgroud)
小智 0
1\xe3\x80\x81CheckboxFeature 添加方法如下:
\n\n public static List<String> getAllCheckboxFeature(String v) {\n return Arrays.asList(Option1.getText(),...Option4.getText());\n }\nRun Code Online (Sandbox Code Playgroud)\n\n
\n2\xe3\x80\x81比使用 jstl 类似:
<c:forEach items="${options}" var="option">\n <input type="checkbox" ="${option}">\n</c:forEach>\nRun Code Online (Sandbox Code Playgroud)\n