我有这样的枚举
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); } }@H_301_3@这将在Web视图中显示四个选项作为复选框
<form:checkBoxes items="${features}" path="enabledFeatures" itemLabel="text" delimiter="<br/>"/>@H_301_3@我该如何翻译这些选项?我对Web视图中的其余翻译使用fmt:message.
我试过了
Option1(" <fmt:message key=\"text.test\"/>"),@H_301_3@和
Option1(" ${option1}"),@H_301_3@同
<fmt:message key="text.select" var="option1"/>@H_301_3@在.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; [...]@H_301_3@我不知道如何在itemLabel属性中嵌套l10n查找,所以我会写如下:
<c:forEach items="Options.values()" var="current"> <form:checkBox path="selectedOptions" value="${current.name()}"/> <fmt:message key="${current.getKey()}"/> </c:forEach>@H_301_3@