尝试使用 JSTL 来创建一个 i18n 应用程序,我有这个:
<li><a href="admin/insertEmployee.jsp"><fmt:message key="new"/></a></li>
但在浏览器上它不会翻译相应的键“new”并显示???new???
而不是在属性文件中定义为 HTML anchor 的值(在 pt_PT 中应该是“Novo”)。
我在一个包下有以下文件:
- 消息.properties
- messages_en_US.properties
- messages_pt_Pt.properties。
试图在 web.xml (pt_PT) 中定义默认语言环境,但仍然无法正常工作...
我需要定义一个 <fmt:setLocale />
吗? ?
这是正确的 URI:
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
在 web.xml 中:
<context-param>
<param-name>
javax.servlet.jsp.jstl.fmt.localizationContext
</param-name>
<param-value>com.arthurportas-i18n.messages</param-value>
</context-param>
<context-param>
<param-name>
javax.servlet.jsp.jstl.fmt.fallbackLocale
</param-name>
<param-value>pt_PT</param-value>
</context-param>
<context-param>
<param-name>
javax.servlet.jsp.jstl.fmt.locale
</param-name>
<param-value>pt_PT</param-value>
</context-param>
最佳答案
@arthur-portas: Only strange behavior is that selecting english translation through clicking on link, requires double click!! A single click is ignored...Is this a browser cache behavior?
那是因为您在 setBundle 之后设置了语言环境。正确的顺序是:
<c:if test="${param['lang'] !=null}">
<fmt:setLocale value="${param['lang']}" scope="session" />
</c:if>
<fmt:setBundle basename="com.arthurportas.i18n.Messages"/>
关于jsp - JSTL i18n fmt 属性设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16310381/