如何翻译.java源文件中的文本?
发布时间:2020-05-24 23:06:23 所属栏目:Java 来源:互联网
导读:我有这样的枚举 public enum CheckboxFeature { Option1( choose this), Option2( or this), Option3( maybe this), Option4( lastly this); @Getter private final String text; p
|
我有这样的枚举 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);
}
}
这将在Web视图中显示四个选项作为复选框 <form:checkboxes items="${features}" path="enabledFeatures" itemLabel="text" delimiter="<br/>"/>
我该如何翻译这些选项?我对Web视图中的其余翻译使用fmt:message. 我试过了 Option1(" <fmt:message key="text.test"/>"),
和 Option1(" ${option1}"),
同 <fmt:message key="text.select" var="option1"/> 在.jsp中. 解决方法最理想的是,您从枚举中获取资源键,并查看它.public enum CheckboxFeature {
Option1("label.option1.key"),Option2("label.option2.key"),Option1("label.option3.key"),Option2("label.option4.key");
private final String key;
[...]
我不知道如何在itemLabel属性中嵌套l10n查找,所以我会写如下: <c:forEach items="Options.values()" var="current">
<form:checkbox path="selectedOptions" value="${current.name()}"/> <fmt:message key="${current.getKey()}"/>
</c:forEach> (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
