public static String canonicalize(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 (int i = 0; i < variantsToKeywords.length; i++) {
            String[] vals = variantsToKeywords[i];
            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 (int i = 0; i < CANONICALIZE_MAP.length; i++) {
            if (CANONICALIZE_MAP[i][0].equals(baseName)) {
                foundVariant = true;

                String[] vals = CANONICALIZE_MAP[i];
                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();
    }
public static String canonicalize ( String localeID ) { LocaleIDParser parser = new LocaleIDParser ( localeID , true ) ; String baseName = parser . getBaseName ( ) ; boolean foundVariant = false ; if ( localeID . equals ( "" ) ) { return "" ; } initCANONICALIZE_MAP ( ) ; for ( int i = 0 ; i < variantsToKeywords . length ; i ++ ) { String [ ] vals = variantsToKeywords [ i ] ; 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 ; } } for ( int i = 0 ; i < CANONICALIZE_MAP . length ; i ++ ) { if ( CANONICALIZE_MAP [ i ] [ 0 ] . equals ( baseName ) ) { foundVariant = true ; String [ ] vals = CANONICALIZE_MAP [ i ] ; parser . setBaseName ( vals [ 1 ] ) ; if ( vals [ 2 ] != null ) { parser . defaultKeywordValue ( vals [ 2 ] , vals [ 3 ] ) ; } break ; } } if ( ! foundVariant ) { if ( parser . getLanguage ( ) . equals ( "nb" ) && parser . getVariant ( ) . equals ( "NY" ) ) { parser . setBaseName ( lscvToID ( "nn" , parser . getScript ( ) , parser . getCountry ( ) , null ) ) ; } } return parser . getName ( ) ; }
<strong>[icu]</strong> Returns the canonical name for the specified locale ID.  This is used to
convert POSIX and other grandfathered IDs to standard ICU form.
@param localeID the locale id
@return the canonicalized id