cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Davanum Srinivas <d...@yahoo.com>
Subject Enhancements to i18n Transformer (was Re: [C2] Any outstanding patches???)
Date Tue, 14 Aug 2001 11:55:04 GMT
Michael, 
Please get the latest C2.1, i have integrated your changes there. FYI, i kept the Namespace
URI as
"http://apache.org/cocoon/i18n/2.0" (NOT 2.1 as in your patch)

Konstantin,
I think these changes should get into C2.0. What is your opinion? If we decide not to sync
the
changes, then i will bump up the Namespace URI in C2.1 CVS to "http://apache.org/cocoon/i18n/2.1".

Thanks,
dims

--- Enke Michael <Michael.Enke@wincor-nixdorf.com> wrote:
> Davanum Srinivas wrote:
> > 
> > Team,
> > 
> > Was out of the loop for a while....Are there any patches that need to get in? There
was one
> from
> > Tom for SQLTransformer (that tom said still needs some work before it can get in).
Anything
> other
> > than that, please repost the patch with "cvs diff" from the latest CVS.
> > 
> > Thanks,
> > dims
> > 
> > =====
> > Davanum Srinivas, JNI-FAQ Manager
> > http://www.jGuru.com/faq/JNI
> 
> 
> At 07 Aug 2001 I posted patches for
> src/org/apache/cocoon/transformation/I18nTransformer.java
> and
> xdocs/i18n-transformer.xml
> 
> I have no access to cvs, thats why I post an ordinary diff -u
> before changes:
> version of xdocs/i18n-transformer.xml: 1.6
> version of src/org/apache/cocoon/transformation/I18nTransformer.java:
> 1.14
> 
> 
> Regards,
> Michael
> 
> > --- i18n-transformer.xml.orig	Tue Aug  7 14:28:16 2001
> +++ i18n-transformer.xml	Tue Aug  7 14:32:56 2001
> @@ -28,11 +28,14 @@
>  						<code>I18nTransformer</code>
>  					</link>
>  				, it uses XML dictionaries for all the i18n data. The namespace of i18n is defined
as
> follows:
> -   				<code>xmlns:i18n="http://apache.org/cocoon/i18n/2.0"</code>
> +   				<code>xmlns:i18n="http://apache.org/cocoon/i18n/2.1"</code>
>  				</p>
>  				<p>
>  				First implementation was developed by <link href="mailto:lassi.immonen@valkeus.com">Lassi
> Immonen</link>. In this implementation syntax was changed according to the <link
> href="http://www.infozone-group.org">Infozone Group's</link> i18n proposal (with
a little
> difference) and some new features were implemented.
>  				</p>
> +				<p>
> +				Enhancements for number, date and time have been contributed by <link
> href="mailto:Michael.Enke@wincor-nixdorf.com">Michael Enke</link>.
> +				</p>
>  			<ul>
>  				<li>Name : i18n</li>
>  				<li>Class: org.apache.cocoon.transformation.I18nTransformer</li>
> @@ -168,10 +171,19 @@
>  				</p>
>  			</s2>
>  			<s2 title="Date, time and number formatting">
> -				<p>To format dates and time according to the current locale use <code><![CDATA[<i18n:date
> src-pattern="dd/MM/yyyy" pattern="dd:MMM:yyyy" value="01/01/2001" />]]></code>.
The
> <code>'src-pattern'</code> attribute will be used to parse the <code>'value'</code>,
then the
> date will be formatted according to the current locale using the format specified by
> <code>'pattern'</code> attribute.
> +				<p>To format dates according to the current locale use <code><![CDATA[<i18n:date
> src-pattern="dd/MM/yyyy" pattern="dd:MMM:yyyy" value="01/01/2001" />]]></code>.
The
> <code>'src-pattern'</code> attribute will be used to parse the <code>'value'</code>,
then the
> date will be formatted according to the current locale using the format specified by
> <code>'pattern'</code> attribute.
> +				</p>
> +				<p>To format time for a locale (e.g. de_DE) use <code><![CDATA[<i18n:time
> src-pattern="dd/MM/yyyy" locale="de_DE" value="01/01/2001" />]]></code>.
The
> <code>'src-pattern'</code> and <code>'pattern'</code> attribute
may also contain
> <code>'short'</code>, <code>'medium'</code>, <code>'long'</code>
or <code>'full'</code>. The
> date will be formatted according to this format.
> +				</p>
> +				<p>To format date and time use <code><![CDATA[<i18n:date-time
/>]]></code>.
> +				</p>
> +				<p>It is also possible to specify a src-locale:  <code><![CDATA[<i18n:date
> src-pattern="short" src-locale="en_US" locale="de_DE"> 12/24/01 </i18n:date>
]]></code> will
> result in 24.12.2001
> +				</p>
> +				<p>
> +				A given real <code>pattern</code> and <code>src-pattern</code>
(not short, medium, long,
> full) overwrites the <code>locale</code> and <code>src-locale</code>.
>  				</p>
>  				<p>
> -					If no pattern was specified then the date will be formatted with the
> <code>DateFormat.DEFAULT</code> format (both date and time). If no value
for the date is
> specified then the current date will be used. E.g.: <code><![CDATA[<i18n:date
]]></code> will
> result in the current date and time, formatted with default localized pattern.
> +					If no pattern was specified then the date will be formatted with the
> <code>DateFormat.DEFAULT</code> format (both date and time). If no value
for the date is
> specified then the current date will be used. E.g.: <code><![CDATA[<i18n:date/>
]]></code> will
> result in the current date, formatted with default localized pattern.
>  				</p>
>  				<p>To format numbers in locale sensitive manner use <code><![CDATA[<i18n:number
> pattern="0.##" value="2.0" />]]></code>. This will be useful for Arabic,
Indian, etc. number
> formatting. Additionally, currencies and percent formatting can be used. E.g.: 
>   				</p>
> > --- I18nTransformer.java.orig	Tue Aug  7 12:36:07 2001
> +++ I18nTransformer.java	Tue Aug  7 14:34:11 2001
> @@ -176,6 +176,27 @@
>   * &lt;/map:match&gt;
>   * </pre>
>   *
> + * <p/>
> + * <ul>
> + *  <li><strong><i18n:date/></strong> gives now only the date.</li>
> + *  <li><strong><i18n:date-time/></strong> gives the date and
time.</li>
> + *  <li><strong><i18n:time/></strong> gives the time.</li>
> + *  <li>For date, date-time and time the pattern and src-pattern attribute 
> + *      may have also values of: "short", "medium",
> + *      "long" or "full".</li>
> + * </ul>
> + * <p/>
> + * <ul>
> + * <li>for date, date-time, time and number a different locale and
> + *     source-locale can be specified:
> + *     <i18n:date src-pattern="short" src-locale="en_US" locale="de_DE">
> + *      12/24/01
> + *     </i18n:date>
> + *     will result in 24.12.2001</li>
> + * <li>A given real pattern and src-pattern (not short, medium, long, full)
> + *     overwrites the locale and src-locale</li>
> + * </ul>
> + * <p/>
>   * Future work coming:
>   *
>   * <ul>
> @@ -186,6 +207,7 @@
>   * @author <a href="mailto:Marcus.Crafter@osa.de">Marcus Crafter</a>
>   * @author <a href="mailto:kpiroumian@flagship.ru">Konstantin Piroumian</a>
>   * @author <a href="mailto:lassi.immonen@valkeus.com">Lassi Immonen</a>
> + * @author <a href="mailto:Michael.Enke@wincor-nixdorf.com">Michael Enke</a>
>   */
>  public class I18nTransformer extends AbstractTransformer
>      implements Composable, Poolable, Configurable {
> @@ -193,10 +215,10 @@
>      protected ComponentManager manager;
>  
>      /**
> -     * The namespace for i18n is "http://apache.org/cocoon/i18n/2.0"
> +     * The namespace for i18n is "http://apache.org/cocoon/i18n/2.1"
>       */
>      public static final String I18N_NAMESPACE_URI =
> -        "http://apache.org/cocoon/i18n/2.0";
> +        "http://apache.org/cocoon/i18n/2.1";
>  
>      //
>      // Dictionary elements and attributes
> @@ -216,12 +238,16 @@
>      public static final String I18N_TRANSLATE_ELEMENT = "translate";
>      public static final String I18N_PARAM_ELEMENT = "param";
>      public static final String I18N_DATE_ELEMENT = "date";
> +    public static final String I18N_DATE_TIME_ELEMENT = "date-time";
> +    public static final String I18N_TIME_ELEMENT = "time";
>      public static final String I18N_NUMBER_ELEMENT = "number";
>  
>      // number and date formatting attributes
>      public static final String I18N_SRC_PATTERN_ATTRIBUTE = "src-pattern";
>      public static final String I18N_PATTERN_ATTRIBUTE = "pattern";
>      public static final String I18N_VALUE_ATTRIBUTE = "value";
> +    public static final String I18N_LOCALE_ATTRIBUTE = "locale";
> +    public static final String I18N_SRC_LOCALE_ATTRIBUTE = "src-locale";
>  
>      // configuration parameters
>      public static final String I18N_CATALOGUE_NAME = "catalogue-name";
> @@ -253,7 +279,9 @@
>      private static final int STATE_TRANSLATE_KEY = 5;
>      private static final int STATE_TRANSLATE_TEXT_KEY = 6;
>      private static final int STATE_INSIDE_DATE = 7;
> -    private static final int STATE_INSIDE_NUMBER = 8;
> +    private static final int STATE_INSIDE_DATE_TIME = 8;
> +    private static final int STATE_INSIDE_TIME = 9;
> +    private static final int STATE_INSIDE_NUMBER = 10;
>  
>      /**
>       * Current state of the transformer.
> @@ -316,7 +344,7 @@
>      /**
>       * Locale setting.
>       */
> -    private Locale locale;
> +    private Locale locale, loc, srcLoc;
>  
>      /**
>       * Date element attributes and their values.
> @@ -534,6 +562,24 @@
>  
>                  setFormattingParams(attr);
>                  current_state = STATE_INSIDE_DATE;
> +            } else if (I18N_DATE_TIME_ELEMENT.equals(name)) {
> +                if (current_state != STATE_OUTSIDE) {
> +                    throw new SAXException(this.getClass().getName()
> +                                           + ": i18n:date-time elements are not allowed
"
> +                                           + "inside of other i18n elements.");
> +                }
> +
> +                setFormattingParams(attr);
> +                current_state = STATE_INSIDE_DATE_TIME;
> +            } else if (I18N_TIME_ELEMENT.equals(name)) {
> +                if (current_state != STATE_OUTSIDE) {
> +                    throw new SAXException(this.getClass().getName()
> +                                           + ": i18n:date elements are not allowed "
> +                                           + "inside of other i18n elements.");
> +                }
> +
> +                setFormattingParams(attr);
> +                current_state = STATE_INSIDE_TIME;
>              } else if (I18N_NUMBER_ELEMENT.equals(name)) {
>                  if (current_state != STATE_OUTSIDE) {
>                      throw new SAXException(this.getClass().getName()
> @@ -573,6 +619,16 @@
>              formattingParams.put(I18N_VALUE_ATTRIBUTE, attr_value);
>          }
>  
> +        attr_value = attr.getValue(I18N_LOCALE_ATTRIBUTE);
> +        if (attr_value != null) {
> +            formattingParams.put(I18N_LOCALE_ATTRIBUTE, attr_value);
> +        }
> +
> +        attr_value = attr.getValue(I18N_SRC_LOCALE_ATTRIBUTE);
> +        if (attr_value != null) {
> +            formattingParams.put(I18N_SRC_LOCALE_ATTRIBUTE, attr_value);
> +        }
> +
>          attr_value = attr.getValue(I18N_TYPE_ATTRIBUTE);
>          if (attr_value != null) {
>              formattingParams.put(I18N_TYPE_ATTRIBUTE, attr_value);
> @@ -605,8 +661,10 @@
>                      break;
>                  }
>              case STATE_INSIDE_DATE:
> +            case STATE_INSIDE_DATE_TIME:
> +            case STATE_INSIDE_TIME:
>                  {
> -                    endDateElement();
> +                    endDate_TimeElement();
>                      break;
>                  }
>              case STATE_INSIDE_NUMBER:
> @@ -688,6 +746,9 @@
>                  break;
>              }
>          case STATE_INSIDE_DATE:
> +        case STATE_INSIDE_DATE_TIME:
> +        case STATE_INSIDE_TIME:
> +        case STATE_INSIDE_NUMBER:
>              {
>                  if (formattingParams != null) {
>                      if (formattingParams.get(I18N_VALUE_ATTRIBUTE) == null) {
> @@ -699,18 +760,6 @@
>                  }
>                  break;
>              }
> -        case STATE_INSIDE_NUMBER:
> -            {
> -                if (formattingParams != null) {
> -                    if (formattingParams.get(I18N_PATTERN_ATTRIBUTE) == null) {
> -                        formattingParams.put(I18N_PATTERN_ATTRIBUTE, key);
> -                    } else {
> -                        // how to use the text inside of number element?
> -                    }
> -
> -                }
> -                break;
> -            }
>          default:
>              {
>                  throw new SAXException(this.getClass().getName()
> @@ -812,9 +861,11 @@
>                      debug("Put param value: " + param_value);
>                      formattingParams.put(I18N_VALUE_ATTRIBUTE, param_value);
>                  }
> -                if ("date".equals(paramType)) {
> -                    debug("Formatting date param: " + formattingParams);
> -                    param_value = formatDate(formattingParams);
> +                if ("date".equals(paramType) ||
> +		    "date-time".equals(paramType) ||
> +		    "time".equals(paramType)) {
> +                    debug("Formatting date_time param: " + formattingParams);
> +                    param_value = formatDate_Time(formattingParams);
>                  } else if ("number".equals(paramType)) {
>                      debug("Formatting number param: " + formattingParams);
>                      param_value = formatNumber(formattingParams);
> @@ -848,17 +899,43 @@
>          current_state = STATE_OUTSIDE;
>      }
>  
> -    private void endDateElement() throws SAXException {
> -        String result = formatDate(formattingParams);
> +    private void endDate_TimeElement() throws SAXException {
> +        String result = formatDate_Time(formattingParams);
>          super.contentHandler.characters(result.toCharArray(), 0, result.length());
>          current_state = STATE_OUTSIDE;
>      }
>  
> -    private String formatDate(Map params) throws SAXException {
> +    private Locale getLocale(Map params, String attribute) {
> +	Locale locale = this.locale;
> 
=== message truncated ===> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
> For additional commands, email: cocoon-dev-help@xml.apache.org


=====
Davanum Srinivas, JNI-FAQ Manager
http://www.jGuru.com/faq/JNI

__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Mime
View raw message