cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Davanum Srinivas <d...@yahoo.com>
Subject Re: [C2][i18n] Patches for i18nTransformer2
Date Fri, 15 Jun 2001 15:03:06 GMT
Konstantin,
Done. Please cross-check. If all's well, i will remove the old one.

Thanks,
dims

--- "Piroumian, Konstantin" <KPiroumian@flagship.ru> wrote:
>  > All your samples are working now. Can you please resubmit all the patches
>  against the latest CVS.
>  
>  Fine! Changes are attached.
>  
>  For Windows users' information, the correct new line character in UTF-8 is
>  LF (#10). I've got a lot of differences in the dictionary file, because of
>  the wrong character. It was CRLF (#13#10), then I changed it to LF only
>  (#10) and differences disappeared.
>  
>  > dims
>  
>  Kot.
>  
>  
>  
> 
> > ? build
> ? i18n_diff.txt
> Index: src/org/apache/cocoon/transformation/I18nTransformer2.java
> ===================================================================
> RCS file:
> /home/cvspublic/xml-cocoon2/src/org/apache/cocoon/transformation/I18nTransformer2.java,v
> retrieving revision 1.9
> diff -u -r1.9 I18nTransformer2.java
> --- src/org/apache/cocoon/transformation/I18nTransformer2.java	2001/06/01 16:14:57	1.9
> +++ src/org/apache/cocoon/transformation/I18nTransformer2.java	2001/06/15 13:19:21
> @@ -37,8 +37,15 @@
>  import java.util.StringTokenizer;
>  import java.util.ArrayList;
>  import java.util.Locale;
> +import java.util.Date;
>  
> +import java.text.Format;
>  import java.text.MessageFormat;
> +import java.text.DateFormat;
> +import java.text.SimpleDateFormat;
> +import java.text.NumberFormat;
> +import java.text.DecimalFormat;
> +import java.text.ParseException;
>  
>  import java.net.URL;
>  import java.net.MalformedURLException;
> @@ -132,23 +139,43 @@
>      public final static String I18N_DATE_ELEMENT = "date";
>      public final static String I18N_NUMBER_ELEMENT = "number";
>  
> +    // number and date formatting attributes
> +    public final static String I18N_SRC_PATTERN_ATTRIBUTE = "src-pattern";
> +    public final static String I18N_PATTERN_ATTRIBUTE = "pattern";
> +    public final static String I18N_VALUE_ATTRIBUTE = "value";
> +    /**
> +     * <code>sub-type</code> attribute is used with <code>i18:number</code>
to indicate
> +     * a sub-type: <code>currency</code> or <code>percent</code>.
> +     */
> +    public final static String I18N_SUB_TYPE_ATTRIBUTE = "sub-type";
> +    /**
> +     * <code>type</code> attribute is used with <code>i18:param</code>
to indicate
> +     * the parameter type: <code>date</code> or <code>number</code>.
> +     * If <code>type</code> is <code>number</code> then a <code>sub-type</code>
> +     * can be used.
> +     */
> +    public final static String I18N_TYPE_ATTRIBUTE = "type";
> +
>      // States of the transformer
>      private final static int STATE_OUTSIDE = 0;
>      private final static int STATE_INSIDE_TEXT = 1;
>      private final static int STATE_INSIDE_PARAM = 2;
>      private final static int STATE_INSIDE_TRANSLATE = 3;
> -//    private final static int STATE_INSIDE_PARAM_TEXT = 4;
> -    private final static int STATE_INSIDE_TRANSLATE_TEXT = 5;
> -    private final static int STATE_TRANSLATE_KEY = 6;
> -    private final static int STATE_TRANSLATE_TEXT_KEY = 7;
> +    private final static int STATE_INSIDE_TRANSLATE_TEXT = 4;
> +    private final static int STATE_TRANSLATE_KEY = 5;
> +    private final static int STATE_TRANSLATE_TEXT_KEY = 6;
> +    private final static int STATE_INSIDE_DATE = 7;
> +    private final static int STATE_INSIDE_NUMBER = 8;
>  
>      /**
>       * Current state of the transformer.
> +     * The value is STATE_OUTSIDE by default.
>       */
>      private int current_state = STATE_OUTSIDE;
>  
>      /**
> -     * Previous state. Used to translate text inside params and translate elements.
> +     * Previous state.
> +     * Used to translate text inside params and translate elements.
>       */
>       private int prev_state = STATE_OUTSIDE;
>  
> @@ -205,13 +232,33 @@
>       * Also, different encodings can be specified: ru_RU_koi8
>       */
>      private Locale locale;
> +
> +    /**
> +     * Date element attributes and their values.
> +     */
> +    private HashMap formattingParams;
> +
> +    public static Locale parseLocale(String locale) {
> +        StringTokenizer st = new StringTokenizer(locale, "_");
> +        String lang = null;
> +        String country = null;
> +        String variant = null;
> +        if (!st.hasMoreTokens()) {
> +            return Locale.ENGLISH;
> +        }
> +        else {
> +            lang = st.nextToken();
> +        }
>  
> -    public void setLang(String lang) {
> -        this.lang = lang;
> +        country = st.hasMoreTokens() ? st.nextToken() : "";
> +        variant = st.hasMoreTokens() ? st.nextToken() : "";
> +
> +        return new Locale(lang, country, variant);
>      }
>  
>      public void setLocale(Locale locale) {
>          this.locale = locale;
> +        this.lang = locale.getLanguage();
>      }
>  
>      /**
> @@ -228,26 +275,8 @@
>          if (lang == null) {
>              lang = LangSelect.getLang(objectModel, parameters);
>          }
> -        setLang(lang);
>  
> -        Locale locale = null;
> -        int ind = lang.indexOf("_");
> -        if (ind != -1) {
> -            int lind = lang.lastIndexOf("_");
> -            if (ind == lind) {
> -                locale = new Locale(lang.substring(0, ind - 1),
> -                    lang.substring(ind + 1));
> -            }
> -            else {
> -                locale = new Locale(lang.substring(0, ind - 1),
> -                    lang.substring(ind + 1, lind - 1),
> -                    lang.substring(lind + 1));
> -            }
> -        }
> -        else {
> -            locale = new Locale(lang, "");
> -        }
> -        setLocale(locale);
> +        setLocale(parseLocale(lang));
>          formatter.setLocale(locale);
>  
>          // FIXME (KP)
> @@ -307,51 +336,126 @@
>      private void startI18NElement(String name, Attributes attr)
>      throws SAXException {
>          this.getLogger().debug("Start i18n element: " + name);
> -        if (I18N_TEXT_ELEMENT.equals(name)) {
> -            if (current_state != STATE_OUTSIDE
> -                && current_state != STATE_INSIDE_PARAM
> -                && current_state != STATE_INSIDE_TRANSLATE) {
> -                throw new SAXException(this.getClass().getName()
> -                    + ": nested i18n:text elements are not allowed. Current state: "
+
> current_state);
> +        try {
> +            if (I18N_TEXT_ELEMENT.equals(name)) {
> +                if (current_state != STATE_OUTSIDE
> +                    && current_state != STATE_INSIDE_PARAM
> +                    && current_state != STATE_INSIDE_TRANSLATE) {
> +                    throw new SAXException(this.getClass().getName()
> +                        + ": nested i18n:text elements are not allowed. Current state:
" +
> current_state);
> +                }
> +                prev_state = current_state;
> +                current_state = STATE_INSIDE_TEXT;
> +                current_key = attr.getValue(I18N_NAMESPACE_URI, I18N_KEY_ATTRIBUTE);
>              }
> -            prev_state = current_state;
> -            current_state = STATE_INSIDE_TEXT;
> -            current_key = attr.getValue(I18N_NAMESPACE_URI, I18N_KEY_ATTRIBUTE);
> -        }
> -        else if (I18N_TRANSLATE_ELEMENT.equals(name)) {
> -            if (current_state != STATE_OUTSIDE) {
> -//                throw new SAXException(this.getClass().getName()
> -//                    + ": i18n:translate element must be used "
> -//                    + "outside of other i18n elements. Current state: " + current_state);
> +            else if (I18N_TRANSLATE_ELEMENT.equals(name)) {
> +                if (current_state != STATE_OUTSIDE) {
> +                    throw new SAXException(this.getClass().getName()
> +                        + ": i18n:translate element must be used "
> +                        + "outside of other i18n elements. Current state: " + current_state);
> +                }
> +                current_state = STATE_INSIDE_TRANSLATE;
>              }
> -            current_state = STATE_INSIDE_TRANSLATE;
> -        }
> -        else if (I18N_PARAM_ELEMENT.equals(name)) {
> -            if (current_state != STATE_INSIDE_TRANSLATE) {
> -                throw new SAXException(this.getClass().getName()
> -                    + ": i18n:param element can be used only inside "
> -                    + "i18n:translate element. Current state: " + current_state);
> +            else if (I18N_PARAM_ELEMENT.equals(name)) {
> +                if (current_state != STATE_INSIDE_TRANSLATE) {
> +                    throw new SAXException(this.getClass().getName()
> +                        + ": i18n:param element can be used only inside "
> +                        + "i18n:translate element. Current state: " + current_state);
> +                }
> +                setFormattingParams(attr);
> +                current_state = STATE_INSIDE_PARAM;
>              }
> -            current_state = STATE_INSIDE_PARAM;
> +            else if (I18N_DATE_ELEMENT.equals(name)) {
> +                if (current_state != STATE_OUTSIDE) {
> +                    throw new SAXException(this.getClass().getName()
> +                        + ": i18n:date elements are not allowed "
> 
=== 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!?
Spot the hottest trends in music, movies, and more.
http://buzz.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