I looked for some good internationalization tags on the web and haven't been
able to find any that would work for what I'm trying to do: namely autosense
the user's browser language, pick up the appropriate bundle (based on their
prefernece order) and allow automatic formatting using
java.text.MessageFormat.

So we wrote our own, and decided it was in our best interest to submit these
to the taglibs project, so that others wouldn't have to dupliate this effort
and so that (assuming these tags are adopted) we'd be using the standard
rather than something we have to continue to maintain ourselves.  The whole
maintenance argument is what really won this over with mgmt. :-)  At the
bottom of this message is a high level description of the library.

Please advise on how I might submit this to the appropriate channels.

Thanks,

Tim Dawson
Chief Architect
WAM!NET Inc.

-----

There are four tags in the library: localize, messgage, messageArg, and
require.

LocalizeTag senses the user's browser preference and loads the bundle for
the appropriate locale.  If their first request is not found, it looks for
their second preference, and so on. If none of these are found, it uses the
default locale specified by the java runtime.

It also logs (using log4j) when a requested locale is not provided, which
allows you to capture demand for certain languages if you want to.

If the bundle is not provided, it looks in the web app's deployment
descriptor for a "defaultBundle" environment variable.  This allows one to
use the same bundle for an entire webapp (which works nicely for small ones,
but I wouldn't recommend it for large ones).

Example:
  <i18n:localize bundle="com.wamnet.tools.jsptags.i18n-test"/>

MessageTag looks up a key in the user's browser and formats the value for
display to the user. Any body inside the tag is displayed only if a value is
not found for the key.

Examples:
  <i18n:message key="test1"/>

  <i18n:message key="test2">
     alternate html/jsp to evaluate and/or display if test2 is not defined
for a locale
  </i18n:message>

MessageArgumentTag works with MessageTag to use the java.text.MessageFormat
object based on user locales.  It only works when nested inside a
MessageArgument.  In the example below test2 is mapped to "{0,date,short}
{1,number,currency}" which automatically formats the date and currency
according to the defaults, but a given locale could override that if it
wanted to be really picky.

Example:
  <i18n:message key="test2">
    <i18n:messageArg value="<%= dateArg %>"/>
    <i18n:messageArg value="<%= numberArg %>"/>
  </i18n:message>

The last tag, RequireTag, is used for eliminating functionality from a web
page when it is not currently available in the requested language. In the
example below, the key GoUSA was only defined in the
com.wamnet.tools.jsptags.i18n-test_en_US.properties file.

Example:
  <i18n:require key="GoUSA">
  Ha Ha, only Americans get to see this!
  <%
  for (int i=0; i<10; i++)
    {
    if ( i > 0 )
      {
      out.print(", ");
      }
    out.print(i);
    }
  %>
  </i18n:require>

The last tag is the only one I think needs a bit more work.  I've been
thinking about modifying this to work more like ant and supporting text both
if the key is defined and if it is NOT defined, i.e. <i18n:if key="GoUSA">
and <i18n:unless key="GoUSA">.

Reply via email to