jakarta-taglibs-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pier...@apache.org
Subject cvs commit: jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt SetLocaleSupport.java
Date Tue, 21 Oct 2003 00:23:10 GMT
pierred     2003/10/20 17:23:10

  Modified:    standard/src/org/apache/taglibs/standard/tag/common/fmt
                        SetLocaleSupport.java
  Log:
  Fixed findFormattingMatch() to properly handle a preferred locale
  that specifies a variant. With the old code, 'fr_FR_EUR' would
  be matched with 'fr' and not 'fr_FR'.  A Euro currency would therefore
  not be displayed properly. This fix takes care of that.
  
  Revision  Changes    Path
  1.14      +30 -20    jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/SetLocaleSupport.java
  
  Index: SetLocaleSupport.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/SetLocaleSupport.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- SetLocaleSupport.java	15 Jul 2003 23:37:16 -0000	1.13
  +++ SetLocaleSupport.java	21 Oct 2003 00:23:10 -0000	1.14
  @@ -455,9 +455,12 @@
        *
        * The best match is given as the first available locale that exactly
        * matches the given preferred locale ("exact match"). If no exact match
  -     * exists, the best match is given as the first available locale that 
  -     * matches the preferred locale's language component and does not have any
  -     * country component ("language match").
  +     * exists, the best match is given to an available locale that meets
  +     * the following criteria (in order of priority):
  +     *  - available locale's variant is empty and exact match for both
  +     *    language and country
  +     *  - available locale's variant and country are empty, and exact match 
  +     *    for language.
        *
        * @param pref the preferred locale
        * @param avail the available formatting locales
  @@ -467,23 +470,30 @@
        */
       private static Locale findFormattingMatch(Locale pref, Locale[] avail) {
   	Locale match = null;
  -
  -	for (int i=0; i<avail.length; i++) {
  -	    if (pref.equals(avail[i])) {
  -		// Exact match
  -		match = avail[i];
  -		break;
  -	    } else {
  -		if (pref.getLanguage().equals(avail[i].getLanguage())
  -		        && ("".equals(avail[i].getCountry()))) {
  -		    // Language match
  -		    if (match == null) {
  -			match = avail[i];
  -		    }
  -		}
  -	    }
  -	}
  -
  +        boolean langAndCountryMatch = false;
  +        for (int i=0; i<avail.length; i++) {
  +            if (pref.equals(avail[i])) {
  +                // Exact match
  +                match = avail[i];
  +                break;
  +            } else if (
  +                    !"".equals(pref.getVariant()) &&
  +                    "".equals(avail[i].getVariant()) &&
  +                    pref.getLanguage().equals(avail[i].getLanguage()) &&
  +                    pref.getCountry().equals(avail[i].getCountry())) {
  +                // Language and country match; different variant
  +                match = avail[i];
  +                langAndCountryMatch = true;
  +            } else if (
  +                    !langAndCountryMatch &&
  +                    pref.getLanguage().equals(avail[i].getLanguage()) &&
  +                    ("".equals(avail[i].getCountry()))) {
  +                // Language match
  +                if (match == null) {
  +                    match = avail[i];
  +                }
  +            }
  +        }
   	return match;
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-dev-help@jakarta.apache.org


Mime
View raw message