tdawson 01/10/15 21:06:07 Modified: i18n/examples/web bundle_multiple.jsp index.jsp Log: updated and improved examples Revision Changes Path 1.3 +58 -6 jakarta-taglibs/i18n/examples/web/bundle_multiple.jsp Index: bundle_multiple.jsp =================================================================== RCS file: /home/cvs/jakarta-taglibs/i18n/examples/web/bundle_multiple.jsp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- bundle_multiple.jsp 2001/10/14 22:22:50 1.2 +++ bundle_multiple.jsp 2001/10/16 04:06:07 1.3 @@ -1,5 +1,4 @@ <%@ taglib uri="http://jakarta.apache.org/taglibs/i18n-1.0" prefix="i18n" %> - <i18n:bundle baseName="org.apache.taglibs.i18n.i18n-test" id="bundle1"/> @@ -11,13 +10,66 @@ <TITLE>Examples of I18N Custom Tag Library Tag Usage</TITLE> </HEAD> <BODY> - -<i18n:message bundleRef="bundle1" key="test1"/><P/> -<i18n:message bundleRef="bundle2" key="test1"/><P/> +This page shows how multiple bundles can be used together by declaring +scripting variables and by nesting the i18n:message tags inside an +i18n:bundle tag. It also shows various ways of specifying the locale +to an i18n:bundle tag. +<hr/> +Bundles that define scripting variables can be accessed by message tags +with a <b>bundleRef</b> attribute. Both bundles below use the default +browser locale for the bundle. +<pre> +<i18n:bundle baseName="org.apache.taglibs.i18n.i18n-test" + id="bundle1"/> +<i18n:bundle baseName="org.apache.taglibs.i18n.i18n-test2" + id="bundle2"/> +default:test1 = <i18n:message key="test1"/><br/> +bundle1:test1 = <i18n:message bundleRef="bundle1" key="test1"/><br/> +bundle2:test1 = <i18n:message bundleRef="bundle2" key="test1"/><br/> +</pre> +default:test1 = <i18n:message key="test1"/><br/> +bundle1:test1 = <i18n:message bundleRef="bundle1" key="test1"/><br/> +bundle2:test1 = <i18n:message bundleRef="bundle2" key="test1"/><br/> +<hr/> +Message nested inside a bundle tag - locale from session. (<%= session.getAttribute("userLocale") %>) + <pre> + <i18n:bundle baseName="org.apache.taglibs.i18n.i18n-test" + localeAttribute="userLocale"> + <i18n:message key="test1"/> + </i18n:bundle> + </pre> +<i> +<i18n:bundle baseName="org.apache.taglibs.i18n.i18n-test" + localeAttribute="userLocale"> + <i18n:message key="test1"/> +</i18n:bundle> +</i> +<hr/> +Message nested inside a bundle tag - locale from browser. (<%= bundle1.getLocale() %>) + <pre> + <i18n:bundle baseName="org.apache.taglibs.i18n.i18n-test"> + <i18n:message key="test1"/> + </i18n:bundle> + </pre> +<i> <i18n:bundle baseName="org.apache.taglibs.i18n.i18n-test"> -<i18n:message key="test1"/><P/> + <i18n:message key="test1"/> </i18n:bundle> - +</i> +<hr/> +Message nested inside a bundle tag - locale hardcoded. (Locale.US) + <pre> + <i18n:bundle baseName="org.apache.taglibs.i18n.i18n-test"> + locale="<%= java.util.Locale.US %>"> + <i18n:message key="test1"/> + </i18n:bundle> + </pre> +<i> +<i18n:bundle baseName="org.apache.taglibs.i18n.i18n-test" + locale="<%= java.util.Locale.US %>"> + <i18n:message key="test1"/> +</i18n:bundle> +</i> </BODY> </HTML> 1.3 +27 -20 jakarta-taglibs/i18n/examples/web/index.jsp Index: index.jsp =================================================================== RCS file: /home/cvs/jakarta-taglibs/i18n/examples/web/index.jsp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- index.jsp 2001/06/13 03:24:38 1.2 +++ index.jsp 2001/10/16 04:06:07 1.3 @@ -5,31 +5,36 @@ if ( "en".equals(lang) ) { session.setAttribute("userLocale",Locale.ENGLISH); - response.sendRedirect("locale_attribute.jsp"); + // redirect to remove the ?userLocale= parameter + response.sendRedirect("index.jsp"); return; } else if ( "en-US".equals(lang) ) { session.setAttribute("userLocale",Locale.US); - response.sendRedirect("locale_attribute.jsp"); + // redirect to remove the ?userLocale= parameter + response.sendRedirect("index.jsp"); return; } else if ( "fr".equals(lang) ) { session.setAttribute("userLocale",Locale.FRENCH); - response.sendRedirect("locale_attribute.jsp"); + // redirect to remove the ?userLocale= parameter + response.sendRedirect("index.jsp"); return; } else if ( "ja".equals(lang) ) { session.setAttribute("userLocale",Locale.JAPANESE); - response.sendRedirect("locale_attribute.jsp"); + // redirect to remove the ?userLocale= parameter + response.sendRedirect("index.jsp"); return; } - else if ( "".equals(lang) ) + else if ( "browser".equals(lang) ) { - session.invalidate(); - response.sendRedirect("locale_browser.jsp"); + session.removeAttribute("userLocale"); + // redirect to remove the ?userLocale= parameter + response.sendRedirect("index.jsp"); return; } %> @@ -42,18 +47,20 @@ </HEAD> <BODY> The <b>i18n</b> tag library contains tags to support internationalization and localization. -<hr> - -Please select one of the following locales to test: -<br><a href="index.jsp?language=en">English</a> -<br><a href="index.jsp?language=en-US">US English</a> -<br><a href="index.jsp?language=fr">French</a> -<br><a href="index.jsp?language=ja">Japanese</a> -<br><a href="index.jsp?language=">Use Browser Settings</a> -<p> -<br><a href="bundle_multiple.jsp">View Multiple Bundles in Action</a> -<a href="bundle_multiple.txt">(source)</a> -<br><a href="bundle_contents.jsp">Show Bundle Contents</a> -<a href="bundle_contents.txt">(source)</a> +<hr/> +Current userLocale is <b><%= session.getAttribute("userLocale") %></b>. +Please select one of the following locales to test:<br> +(<a href="index.jsp?language=en">English</a>) +(<a href="index.jsp?language=en-US">US English</a>) +(<a href="index.jsp?language=fr">French</a>) +(<a href="index.jsp?language=ja">Japanese</a>) +(<a href="index.jsp?language=browser">Browser Default</a>) +<hr/><p/> +<a href="locale_attribute.jsp">Message Tags Example Page</a><br/> +<a href="format.jsp">Format Tags Example Page</a><br/> +<a href="bundle_multiple.jsp">View Multiple Bundles in Action</a> + <a href="bundle_multiple.txt">(source)</a><br/> +<a href="bundle_contents.jsp">Show Bundle Contents</a> + <a href="bundle_contents.txt">(source)</a><br/> </BODY> </HTML>
