Translation taglib ver. 1.4

    Custom JSP taglib. Lets you proceed templates in your JSP pages. Body tag translate lets you replace user defined keys in own body with some predefined values. For example:


<%@ taglib uri="taglib.tld" prefix="tr" %>

<!-- create dictionary -->
<tr:dictionary id="A">
   <tr:add key="$1">first var</tr:add>
   <tr:add key="@2">second var</tr:add>
</tr:dictionary>

<!-- transform text -->
<tr:translate id="A">
   ...
   $1 ... @2 ...
   ...
</tr:translate>

Here substring $1 will be replaced with value first var and substring @2 will be replaced with value second var

Dictionary is just a set of pairs <some key, some value>. Any dictionary is a page scope, request scope, session scope or application scope variable. Name for this variable as well as a scope both are parameters for tag dictionary. You can directly define your keys and values (see above) or import them from some Hashtable (HashMap). For example:


<%
   java.util.Hashtable t=new java.util.Hashtable();
   ...
<%>

<!-- create session scope dictionary and import data -->
<tr:dictionary id="A" scope="session" source="<%=t%>" />

Tag translate uses by default the following delimiters within the text for detecting the possible replacements: \t\r\n<>,.;:-()[]{}= (first is a space). With attribute ignoreDelimiter="true" tag will replace keys within the text "as is", so you can for example use keys with spaces etc.

Tags are:

dictionary

Body tag. Creates dictionary. Parameters are:

1) id Describes a name for variable
2) scope Optional parameter. Describes scope for variable. Possible values are page, request, session or application. Default value is page.
3) source Optional parameter. Describes Hashtable or HashMap for data import.

add

Body tag. Adds a pair to dictionary. Tag's body describes value. Parameters are:

1) key Describes a key

translate

Body tag. Transforms own body according to the given dictionary. Parameters are:

1) id Describes an id for your dictionary
2) scope Optional parameter. Describes a scope for your dictionary. Possible values are page, request, session or application. Default value is page.
3) ignoreDelimiter Optional parameter. Possible values are true or false. If this value is true tag ignores delimiters within the replaced string. Default value is false.
4) cond Optional parameter. Describes a boolean value tag's behavior depends on. Default value is true (translate).

for downloading:

Library: transtag.jar    Description: taglib.tld

© Coldbeans      Comments?

See also Coldtags suite - the largest collection of custom JSP tags.

Also in Coldtags: