ICU-8303 Do not add language und in toLanguageTag() when a locale has only private use.

X-SVN-Rev: 29391
This commit is contained in:
Yoshito Umaoka 2011-02-03 16:41:06 +00:00
parent d8ea46628b
commit 66f9f5a1d2
3 changed files with 26 additions and 10 deletions

View File

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 2010, International Business Machines Corporation and *
* Copyright (C) 2010-2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
@ -398,11 +398,11 @@ public class LanguageTag {
String region = baseLocale.getRegion();
String variant = baseLocale.getVariant();
boolean hasSubtag = false;
String privuseVar = null; // store ill-formed variant subtags
if (language.length() == 0 || !isLanguage(language)) {
tag._language = UNDETERMINED;
} else {
if (language.length() > 0 && isLanguage(language)) {
// Convert a deprecated language code used by Java to
// a new code
if (language.equals("iw")) {
@ -417,10 +417,12 @@ public class LanguageTag {
if (script.length() > 0 && isScript(script)) {
tag._script = canonicalizeScript(script);
hasSubtag = true;
}
if (region.length() > 0 && isRegion(region)) {
tag._region = canonicalizeRegion(region);
hasSubtag = true;
}
if (JDKIMPL) {
@ -451,6 +453,7 @@ public class LanguageTag {
}
if (variants != null) {
tag._variants = variants;
hasSubtag = true;
}
if (!varitr.isDone()) {
// ill-formed variant subtags
@ -494,6 +497,7 @@ public class LanguageTag {
if (extensions != null) {
tag._extensions = extensions;
hasSubtag = true;
}
// append ill-formed variant subtags to private use
@ -507,8 +511,12 @@ public class LanguageTag {
if (privateuse != null) {
tag._privateuse = privateuse;
} else if (tag._language.length() == 0) {
// use "und" if neither language nor privateuse is available
}
if (tag._language.length() == 0 && (hasSubtag || privateuse == null)) {
// use lang "und" when 1) no language is available AND
// 2) any of other subtags other than private use are available or
// no private use tag is available
tag._language = UNDETERMINED;
}

View File

@ -1,6 +1,6 @@
/*
******************************************************************************
* Copyright (C) 2003-2010, International Business Machines Corporation and *
* Copyright (C) 2003-2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
******************************************************************************
*/
@ -2734,7 +2734,9 @@ public final class ULocale implements Serializable {
StringBuilder buf = new StringBuilder();
String subtag = tag.getLanguage();
buf.append(LanguageTag.canonicalizeLanguage(subtag));
if (subtag.length() > 0) {
buf.append(LanguageTag.canonicalizeLanguage(subtag));
}
subtag = tag.getScript();
if (subtag.length() > 0) {
@ -2762,7 +2764,10 @@ public final class ULocale implements Serializable {
subtag = tag.getPrivateuse();
if (subtag.length() > 0) {
buf.append(LanguageTag.SEP).append(LanguageTag.PRIVATEUSE).append(LanguageTag.SEP);
if (buf.length() > 0) {
buf.append(LanguageTag.SEP);
}
buf.append(LanguageTag.PRIVATEUSE).append(LanguageTag.SEP);
buf.append(LanguageTag.canonicalizePrivateuse(subtag));
}

View File

@ -1,6 +1,6 @@
/*
**********************************************************************
* Copyright (c) 2004-2010, International Business Machines
* Copyright (c) 2004-2011, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* Author: Alan Liu
@ -3764,6 +3764,8 @@ public class ULocaleTest extends TestFmwk {
{"it@collation=badcollationtype;colStrength=identical;cu=usd-eur", "it-u-ks-identic"},
{"en_US_POSIX", "en-US-u-va-posix"},
{"en_US_POSIX@calendar=japanese;currency=EUR","en-US-u-ca-japanese-cu-eur-va-posix"},
{"@x=elmer", "x-elmer"},
{"_US@x=elmer", "und-US-x-elmer"},
};
for (int i = 0; i < locale_to_langtag.length; i++) {
@ -3819,6 +3821,7 @@ public class ULocaleTest extends TestFmwk {
{"zh-u-ca-chinese-x-u-ca-chinese", "zh@calendar=chinese;x=u-ca-chinese", NOERROR},
{"fr--FR", "fr", Integer.valueOf(3)},
{"fr-", "fr", Integer.valueOf(3)},
{"x-elmer", "@x=elmer", NOERROR},
};
for (int i = 0; i < langtag_to_locale.length; i++) {