320 likes | 449 Views
Internationalization. I18N. ISO 639 language codes. website specification. Website displays user’s browser’s preferred language on first load User can change language using ‘language toggle’ User stays on same page when using language toggle. Resource Bundles. ctrl + ‘c’. # welcome page
E N D
Internationalization I18N
website specification • Website displays user’s browser’s preferred language on first load • User can change language using ‘language toggle’ • User stays on same page when using language toggle
ctrl + ‘c’ # welcome page greeting=Welcome to the online home of Nice Doggy. introText=Enjoy browsing and learning more about our unique home delivery service bringing you dogs of all kinds for your delight and delectation to your doorstep. # categories Pet\ Dogs=Pet Dogs Dogs\ to\ Eat=Dogs to Eat Hunting\ Dogs=Hunting Dogs Fighting\ Dogs=Fighting Dogs
messages_ko편집 # welcome page greeting=나이스 도기 온라인 홈에 오신것을 환영합니다. introText=즐겁게 브라우즈하세요! 우리는 다양한 개, 옙은, 귀여운, 맛있는, 싸움하는... 고객님의 집으로 배달 가능! # categories Pet\ Dogs=애완 개 Dogs\ to\ Eat=먹을 개 Hunting\ Dogs=사냥 개 Fighting\ Dogs=싸움 개
In header.jspf <%-- language selection widget --%> english| <div class=“bubble"> <a href = "chooseLanguage?language=ko"> 한국</a> </div>
<%-- language selection widget --%> <c:choose> <c:when test="${pageContext.request.locale.language ne 'ko'}"> english </c:when> <c:otherwise> <c:urlvar="url" value="chooseLanguage"> <c:param name="language" value="en"/> </c:url> <div class="bubble"><a href="${url}">english</a></div> </c:otherwise> </c:choose> | <c:choose> <c:when test="${pageContext.request.locale.languageeq 'ko'}"> 한국 </c:when> <c:otherwise> <c:urlvar="url" value="chooseLanguage"> <c:param name="language" value="ko"/> </c:url> <div class="bubble"><a href="${url}">한국</a></div> </c:otherwise> </c:choose>
http header field: Accept-Language ISO-639 language codes Accept-Language: ko, en
request.getLocale().getLanguage(); ${pageContext.request.locale.language}
Get language from Http accept-language header (browser preference) Get language from jstl session object
EL - two kinds of syntax . or [‘ ... ’]
Two kinds of syntax ${applicationScope.categories} or ${applicationScope[‘categories’]}
Get language from ${pageContext.request.locale.language} Get language from ${sessionScope[‘javax.servlet.jsp.jstl.fmt.locale session’]}
<c:choose> <c:when test="${empty sessionScope['javax.servlet.jsp.jstl.fmt.locale.session']}"> <c:choose> <c:when test="${pageContext.request.locale.language ne 'ko'}"> english </c:when> <c:otherwise> <c:url var="url" value="chooseLanguage"> <c:param name="language" value="en"/> </c:url> <div class="bubble"> <a href="${url}">english</a> </div> </c:otherwise> </c:choose> | <c:choose> <c:when test="${pageContext.request.locale.language eq 'ko'}"> 한국 </c:when> <c:otherwise> <c:url var="url" value="chooseLanguage"> <c:param name="language" value="ko"/> </c:url> <div class="bubble"> <a href="${url}">한국</a> </div> </c:otherwise> </c:choose> </c:when> <c:otherwise> <c:choose> <c:when test="${sessionScope['javax.servlet.jsp.jstl.fmt.locale.session'] ne 'ko'}"> english </c:when> <c:otherwise> <c:url var="url" value="chooseLanguage"> <c:param name="language" value="en"/> </c:url> <div class="bubble"> <a href="${url}">english</a> </div> </c:otherwise> </c:choose> | <c:choose> <c:when test="${sessionScope['javax.servlet.jsp.jstl.fmt.locale.session'] ne 'en'}"> 한국 </c:when> <c:otherwise> <c:url var="url" value="chooseLanguage"> <c:param name="language" value="ko"/> </c:url> <div class="bubble"> <a href="${url}">한국</a> </div> </c:otherwise> </c:choose> </c:otherwise> </c:choose>