Hi Konstantin, I finalized the change of sub-type to type for i18n:number and introduced the code again for yet missing types (int-currency, currency-no-unit, int-currency-nu-unit) As new attribute I added fraction-digits="..." for i18n:number so we can now print out gasoline prices etc.
Regards, Michael
--- I18nTransformer.java.orig Wed Apr 3 13:39:27 2002 +++ I18nTransformer.java Wed Apr 3 15:05:34 2002 @@ -270,12 +270,9 @@ * The param can have i18n:text as its value to provide multilungual value. * Parameters can have additional attributes to be used for formatting: * <ul> - * <li><code>type</code> - can be <code>date, date-time, time or - * number</code>. Used to format params before substitution. - * </li> - * <li><code>sub-type</code> - can be <code>currency, percent</code> - * and used with <code>number</code> type to format a given number - * value as a currency or percent. + * <li><code>type</code> - can be <code>date, date-time, time, + * number, currency, currency-no-unit or percent</code>. + * Used to format params before substitution. * </li> * <li><code>value</code> - the value of the param. If no value is * specified then the text inside of the param element will be used. @@ -385,7 +382,7 @@ /** * i18n:number is used to provide a localized number string. Allowed - * attributes are: <code>pattern, src-pattern, locale, src-locale, sub-type + * attributes are: <code>pattern, src-pattern, locale, src-locale, type * </code> * Usage examples: * <pre> @@ -393,7 +390,7 @@ * 1000.0 * </i18n:number> * - * <i18n:number sub-type="currency" /> + * <i18n:number type="currency" /> * </pre> * * If no value is specifies then 0 will be used. @@ -405,21 +402,21 @@ */ public static final String I18N_NUMBER_ELEMENT = "number"; - /** @todo Implement currency element */ + /** currency element */ public static final String I18N_CURRENCY_ELEMENT = "currency"; - /** @todo Implement percent element */ + /** percent element */ public static final String I18N_PERCENT_ELEMENT = "percent"; - /** @todo Implemement integer currency element */ + /** integer currency element */ public static final String I18N_INT_CURRENCY_ELEMENT = "int-currency"; - /** @todo Implement currency without unit element */ + /** currency without unit element */ public static final String I18N_CURRENCY_NO_UNIT_ELEMENT = "currency-no-unit"; - /** @todo Implement integer currency without unit element */ + /** integer currency without unit element */ public static final String I18N_INT_CURRENCY_NO_UNIT_ELEMENT = "int-currency-no-unit"; @@ -516,14 +513,7 @@ */ public static final String I18N_TYPE_ATTRIBUTE = "type"; - /** - * This attribute is used with <code>i18:number</code> to - * indicate a sub-type: <code>currency</code>, <code>int-currency</code> - * or <code>percent</code>. - */ - public static final String I18N_SUB_TYPE_ATTRIBUTE = "sub-type"; - - // Ņonfiguration parameters + // Configuration parameters /** * This configuration parameter specifies the message catalog name. @@ -563,6 +553,13 @@ // FIXME (KP): Why should it be a file? It can be any resource! private static final String FILE = "file:"; + /** + * <code>fraction-digits</code> attribute is used with + * <code>i18:number</code> to + * indicate the number of digits behind the fraction + */ + public static final String I18N_FRACTION_DIGITS_ATTRIBUTE = "fraction-digits"; + // States of the transformer private static final int STATE_OUTSIDE = 0; private static final int STATE_INSIDE_TEXT = 1; @@ -1031,9 +1028,9 @@ formattingParams.put(I18N_TYPE_ATTRIBUTE, attr_value); } - attr_value = attr.getValue(I18N_SUB_TYPE_ATTRIBUTE); - if (attr_value != null) { - formattingParams.put(I18N_SUB_TYPE_ATTRIBUTE, attr_value); + attr_value = attr.getValue( I18N_FRACTION_DIGITS_ATTRIBUTE ); + if ( attr_value != null ) { + formattingParams.put( I18N_FRACTION_DIGITS_ATTRIBUTE, attr_value ); } } @@ -1405,9 +1402,15 @@ String pattern = (String)params.get(I18N_PATTERN_ATTRIBUTE); // the number value String value = (String)params.get(I18N_VALUE_ATTRIBUTE); - // sub-type - String subType = (String)params.get(I18N_SUB_TYPE_ATTRIBUTE); - + // type + String type = (String)params.get(I18N_TYPE_ATTRIBUTE); + // fraction-digits + int fractionDigits = -1; + try { + fractionDigits = Integer.parseInt((String) params.get + ( I18N_FRACTION_DIGITS_ATTRIBUTE )); + } + catch(NumberFormatException nfe) {} // parsed number Number numberValue = null; @@ -1429,7 +1432,7 @@ char dec = from_fmt.getDecimalFormatSymbols().getDecimalSeparator(); int decAt = 0; boolean appendDec = false; - if (subType == null) { + if (type == null) { to_fmt = (DecimalFormat)NumberFormat.getInstance(loc); to_fmt.setMaximumFractionDigits(309); for (int i = value.length() - 1; @@ -1449,16 +1452,34 @@ if (value.charAt(value.length() - 1) == dec) { appendDec = true; } - } else if (subType.equals("currency")) { + } else if (type.equals( I18N_CURRENCY_ELEMENT )) { to_fmt = (DecimalFormat)NumberFormat.getCurrencyInstance(loc); - } else if (subType.equals("int-currency")) { + } else if (type.equals( I18N_INT_CURRENCY_ELEMENT )) { to_fmt = (DecimalFormat)NumberFormat.getCurrencyInstance(loc); int_currency = 1; for (int i = 0; i < to_fmt.getMaximumFractionDigits(); i++) { int_currency *= 10; } - } else if (subType.equals("percent")) { + } else if ( type.equals( I18N_CURRENCY_NO_UNIT_ELEMENT ) ) { + DecimalFormat tmp = (DecimalFormat) NumberFormat.getCurrencyInstance( loc +); + to_fmt = (DecimalFormat) NumberFormat.getInstance( loc ); + to_fmt.setMinimumFractionDigits(tmp.getMinimumFractionDigits()); + to_fmt.setMaximumFractionDigits(tmp.getMaximumFractionDigits()); + } else if ( type.equals( I18N_INT_CURRENCY_NO_UNIT_ELEMENT ) ) { + DecimalFormat tmp = (DecimalFormat) NumberFormat.getCurrencyInstance( loc +); + int_currency = 1; + for ( int i = 0; i < tmp.getMaximumFractionDigits(); i++ ) + int_currency *= 10; + to_fmt = (DecimalFormat) NumberFormat.getInstance( loc ); + to_fmt.setMinimumFractionDigits(tmp.getMinimumFractionDigits()); + to_fmt.setMaximumFractionDigits(tmp.getMaximumFractionDigits()); + } else if (type.equals( I18N_PERCENT_ELEMENT )) { to_fmt = (DecimalFormat)NumberFormat.getPercentInstance(loc); + } + + if(fractionDigits > -1) { + to_fmt.setMinimumFractionDigits(fractionDigits); + to_fmt.setMaximumFractionDigits(fractionDigits); } // pattern overwrites locale format
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]