美文网首页
Build a Multi-Lingual App with J

Build a Multi-Lingual App with J

作者: Zihowe | 来源:发表于2017-07-24 03:19 被阅读21次

tagdemo.i18n.resources 就是存放多语言的数据的文件,defaultmylabels.properties这个文件,当theLocale没有设置或者找不到例如FrenchChinese之类没有预先设置好的语言,就会使用这个default文件。

image.png image.png image.png image.png image.png
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<c:set var="theLocale" 
value="${not empty param.theLocale ? param.theLocale : pageContext.request.locale}"
scope="session" />

<fmt:setLocale value="${theLocale}" />

<fmt:setBundle basename="com.luv2code.jsp.tagdemo.i18n.resources.mylabels" />

<html>

<body>

<a href="i18n-messages-test.jsp?theLocale=en_US">English (US)</a>
 |
<a href="i18n-messages-test.jsp?theLocale=es_ES">Spanish (ES)</a>
 |
<a href="i18n-messages-test.jsp?theLocale=de_DE">German (DE)</a>
 
<hr>

<fmt:message key="label.greeting" /> <br/> <br/>

<fmt:message key="label.firstname" /> <i>John</i> <br/>

<fmt:message key="label.lastname" /> <i>Doe</i> <br/><br/>

<fmt:message key="label.welcome" /> <br/>

<hr>

Selected locale: ${theLocale}

</body>

</html>

相关文章

网友评论

      本文标题:Build a Multi-Lingual App with J

      本文链接:https://www.haomeiwen.com/subject/jnyvkxtx.html