Hi!
We had a problem with a mauve testlet which turned out to be related to
the default locale. CACAO sets the user.country property instead of
the user.region per default. Some websearch
(http://www.kaffe.org/pipermail/kaffe/2004-April/097806.html) and some
testing with sun's 1.5 showed that sun sets the default locale to en_US
when no LANG env is found and uses user.country, but prioritize
user.region is defined on the commandline. This patch changes our
behaviour.
Ok to commit?
TWISTI
2006-03-10 Christian Thalinger <[EMAIL PROTECTED]>
* java/util/Locale.java (defaultLocale): Set to en_US per
default and use user.country but prioritize user.region if
defined.
(getLocale(String language, String country)): Renamed region to
country.
(getLocale(String language, String region, String variant)):
Likewise.
(getAvailableLocales): Likewise.
Index: java/util/Locale.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/util/Locale.java,v
retrieving revision 1.31
diff -u -3 -p -r1.31 Locale.java
--- java/util/Locale.java 13 Sep 2005 21:25:09 -0000 1.31
+++ java/util/Locale.java 10 Mar 2006 14:23:23 -0000
@@ -209,10 +209,18 @@ public final class Locale implements Ser
* null. Note the logic in the main constructor, to detect when
* bootstrapping has completed.
*/
- private static Locale defaultLocale =
- getLocale(SystemProperties.getProperty("user.language", "en"),
- SystemProperties.getProperty("user.region", ""),
- SystemProperties.getProperty("user.variant", ""));
+ private static Locale defaultLocale;
+
+ static {
+ String language = SystemProperties.getProperty("user.language", "en");
+ String country = SystemProperties.getProperty("user.country", "US");
+ String region = SystemProperties.getProperty("user.region", null);
+ String variant = SystemProperties.getProperty("user.variant", "");
+
+ defaultLocale = getLocale(language,
+ (region != null) ? region : country,
+ variant);
+ }
/**
* Array storing all the available two-letter ISO639 languages.
@@ -236,38 +244,38 @@ public final class Locale implements Ser
}
/**
- * Retrieves the locale with the specified language and region
+ * Retrieves the locale with the specified language and country
* from the cache.
*
* @param language the language of the locale to retrieve.
- * @param region the region of the locale to retrieve.
+ * @param country the country of the locale to retrieve.
* @return the locale.
*/
- private static Locale getLocale(String language, String region)
+ private static Locale getLocale(String language, String country)
{
- return getLocale(language, region, "");
+ return getLocale(language, country, "");
}
/**
- * Retrieves the locale with the specified language, region
+ * Retrieves the locale with the specified language, country
* and variant from the cache.
*
* @param language the language of the locale to retrieve.
- * @param region the region of the locale to retrieve.
+ * @param country the country of the locale to retrieve.
* @param variant the variant of the locale to retrieve.
* @return the locale.
*/
- private static Locale getLocale(String language, String region, String
variant)
+ private static Locale getLocale(String language, String country, String
variant)
{
if (localeMap == null)
localeMap = new HashMap(256);
- String name = language + "_" + region + "_" + variant;
+ String name = language + "_" + country + "_" + variant;
Locale locale = (Locale) localeMap.get(name);
if (locale == null)
{
- locale = new Locale(language, region, variant);
+ locale = new Locale(language, country, variant);
localeMap.put(name, locale);
}
@@ -390,23 +398,23 @@ public final class Locale implements Ser
for (int i = 0; i < localeNames.length; i++)
{
String language;
- String region = "";
+ String country = "";
String variant = "";
String name = localeNames[i];
language = name.substring(0, 2);
if (name.length() > 2)
- region = name.substring(3);
+ country = name.substring(3);
- int index = region.indexOf("_");
+ int index = country.indexOf("_");
if (index > 0)
{
- variant = region.substring(index + 1);
- region = region.substring(0, index - 1);
+ variant = country.substring(index + 1);
+ country = country.substring(0, index - 1);
}
- availableLocales[i] = getLocale(language, region, variant);
+ availableLocales[i] = getLocale(language, country, variant);
}
}