* the locale id
* @return the canonicalized id
* @stable ICU 3.0
*/
public static String canonicalize(final String localeID) {
LocaleIDParser parser = new LocaleIDParser(localeID, true);
String baseName = parser.getBaseName();
boolean foundVariant = false;
// formerly, we always set to en_US_POSIX if the basename was empty, but
// now we require that the entire id be empty, so that "@foo=bar"
// will pass through unchanged.
// {dlf} I'd rather keep "" unchanged.
if (localeID.equals("")) {
return "";
// return "en_US_POSIX";
}
// we have an ID in the form xx_Yyyy_ZZ_KKKKK
initCANONICALIZE_MAP();
/* convert the variants to appropriate ID */
for (String[] vals : variantsToKeywords) {
int idx = baseName.lastIndexOf("_" + vals[0]);
if (idx > -1) {
foundVariant = true;
baseName = baseName.substring(0, idx);
if (baseName.endsWith("_")) {
baseName = baseName.substring(0, --idx);
}
parser.setBaseName(baseName);
parser.defaultKeywordValue(vals[1], vals[2]);
break;
}
}
/* See if this is an already known locale */
for (String[] vals : CANONICALIZE_MAP) {
if (vals[0].equals(baseName)) {
foundVariant = true;
parser.setBaseName(vals[1]);
if (vals[2] != null) {
parser.defaultKeywordValue(vals[2], vals[3]);
}
break;
}
}
/* total mondo hack for Norwegian, fortunately the main NY case is handled earlier */
if (!foundVariant) {
if (parser.getLanguage().equals("nb") && parser.getVariant().equals("NY")) {
parser.setBaseName(lscvToID("nn", parser.getScript(), parser.getCountry(), null));
}
}
return parser.getName();
}