You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by br...@apache.org on 2003/05/20 17:49:57 UTC

cvs commit: cocoon-2.1/src/documentation/xdocs/userdocs/transformers i18n-transformer.xml

bruno       2003/05/20 08:49:57

  Modified:    src/java/org/apache/cocoon/transformation
                        I18nTransformer.java
               src/documentation/xdocs/userdocs/transformers
                        i18n-transformer.xml
  Log:
  Applied patch 19894 (dec-and-grp-locale attribute on i18n:number) by Michael Enke.
  
  Revision  Changes    Path
  1.8       +28 -1     cocoon-2.1/src/java/org/apache/cocoon/transformation/I18nTransformer.java
  
  Index: I18nTransformer.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/transformation/I18nTransformer.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- I18nTransformer.java	20 May 2003 15:14:02 -0000	1.7
  +++ I18nTransformer.java	20 May 2003 15:49:56 -0000	1.8
  @@ -624,6 +624,14 @@
       public static final String I18N_TYPE_ATTRIBUTE          = "type";
   
       /**
  +     * This attribute is used to specify a different locale for the
  +     * GroupingSeparator and MonetaryDecimalSeparator.
  +     * This enables to see a currency formatted for Euro but with US
  +     * grouping and decimal char.
  +     */
  +    public static final String I18N_DEC_AND_GRP_LOCALE_ATTRIBUTE = "dec-and-grp-locale";
  +
  +    /**
        * This attribute can be used on <code>i18n:text</code> to indicate the catalogue
        * from which the key should be retrieved. This attribute is optional,
        * if it is not mentioned the default catalogue is used.
  @@ -1396,6 +1404,11 @@
               formattingParams.put(I18N_LOCALE_ATTRIBUTE, attr_value);
           }
   
  +        attr_value = attr.getValue(I18N_DEC_AND_GRP_LOCALE_ATTRIBUTE);
  +        if (attr_value != null) {
  +            formattingParams.put(I18N_DEC_AND_GRP_LOCALE_ATTRIBUTE, attr_value);
  +        }
  +
           attr_value = attr.getValue(I18N_SRC_LOCALE_ATTRIBUTE);
           if (attr_value != null) {
               formattingParams.put(I18N_SRC_LOCALE_ATTRIBUTE, attr_value);
  @@ -1456,6 +1469,8 @@
           }
           // Trim text values to avoid parsing errors.
           textValue = textValue.trim();
  +        if (textValue.length() == 0)
  +            return;
   
           debug( "i18n message text = '" + textValue + "'" );
   
  @@ -1871,6 +1886,8 @@
           // locale, may be switched locale
           Locale loc = getLocale(params, I18N_LOCALE_ATTRIBUTE);
           Locale srcLoc = getLocale(params, I18N_SRC_LOCALE_ATTRIBUTE);
  +        // Decimal and Grouping locale
  +        Locale dgLoc = getLocale(params, I18N_DEC_AND_GRP_LOCALE_ATTRIBUTE);
   
           // src format
           DecimalFormat from_fmt = (DecimalFormat)NumberFormat.getInstance(srcLoc);
  @@ -1937,6 +1954,16 @@
           if(fractionDigits > -1) {
               to_fmt.setMinimumFractionDigits(fractionDigits);
               to_fmt.setMaximumFractionDigits(fractionDigits);
  +        }
  +
  +        if(dgLoc != null) {
  +            DecimalFormat _df = (DecimalFormat)NumberFormat.getCurrencyInstance(dgLoc);
  +            DecimalFormatSymbols _dfsNew = _df.getDecimalFormatSymbols();
  +            DecimalFormatSymbols _dfsOrig = to_fmt.getDecimalFormatSymbols();
  +            _dfsOrig.setDecimalSeparator(_dfsNew.getDecimalSeparator());
  +            _dfsOrig.setMonetaryDecimalSeparator(_dfsNew.getMonetaryDecimalSeparator());
  +            _dfsOrig.setGroupingSeparator(_dfsNew.getGroupingSeparator());
  +            to_fmt.setDecimalFormatSymbols(_dfsOrig);
           }
   
           // pattern overwrites locale format
  
  
  
  1.3       +11 -0     cocoon-2.1/src/documentation/xdocs/userdocs/transformers/i18n-transformer.xml
  
  Index: i18n-transformer.xml
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/documentation/xdocs/userdocs/transformers/i18n-transformer.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- i18n-transformer.xml	26 Mar 2003 07:55:13 -0000	1.2
  +++ i18n-transformer.xml	20 May 2003 15:49:57 -0000	1.3
  @@ -253,6 +253,17 @@
                           <li><code><![CDATA[<i18n:number type="int-currency-no-unit" value="170374" />]]></code> will result in localized presentation of the value for US locale: 1,703.74, and 170374 (without currency unit) for a currency without subunit.</li>
                           <li><code><![CDATA[<i18n:number type="percent" value="1.2" />]]></code> will result in localized percent value: %120 for most of the locales.</li>
                       </ul>
  +                <p>
  +                 If someone from US want to see sales figures from a store in Germany,
  +                 the value is formatted with locale="de_DE", e.g.
  +                 100,00 &#x20AC;. The decimal and grouping separator than is also in de_DE locale.
  +                 This may be leading to some confusion/misunderstanding because
  +                 people from US know the "," as thousand separator.
  +
  +                 There is a attribute called "dec-and-grp-locale", so that the output from
  +                 <code><![CDATA[<i18n:number type="currency" locale="de_DE" dec-and-grp-locale="en_US">100</i18n:number>]]></code>
  +                 results in 100.00 &#x20AC;
  +                </p>
                   <anchor id="i18n_param"/><p>
                       Also, date and number formatting can be used with substitution params. <code>type</code> attribute must be used with params to indicate the param type (date, number, currency, ...). Default type is <code>string</code>.
                   </p>