public static function canonicalize($locale)
    {
        if (empty($locale)) {
            return $locale;
        }

        $locale = str_replace('_', '-', strtolower($locale));
        $localeParts = explode('-', $locale);
        foreach ($localeParts as $index => $part) {
            if ($index === 0) {
                // The language code should stay lowercase.
                continue;
            }

            if (strlen($part) == 4) {
                // Script code.
                $localeParts[$index] = ucfirst($part);
            } else {
                // Country or variant code.
                $localeParts[$index] = strtoupper($part);
            }
        }

        return implode('-', $localeParts);
    }
public static function canonicalize($locale)
    {
        if (empty($locale)) {
            return $locale;
        }

        $locale = str_replace('_', '-', strtolower($locale));
        $localeParts = explode('-', $locale);
        foreach ($localeParts as $index => $part) {
            if ($index === 0) {
                // The language code should stay lowercase.
                continue;
            }

            if (strlen($part) == 4) {
                // Script code.
                $localeParts[$index] = ucfirst($part);
            } else {
                // Country or variant code.
                $localeParts[$index] = strtoupper($part);
            }
        }

        return implode('-', $localeParts);
    }
public static function canonicalize ( $ locale ) { if ( empty ( $ locale ) ) { return $ locale ; } $ locale = str_replace ( '_' , '-' , strtolower ( $ locale ) ) ; $ localeParts = explode ( '-' , $ locale ) ; foreach ( $ localeParts as $ index => $ part ) { if ( $ index === 0 ) { // The language code should stay lowercase. continue ; } if ( strlen ( $ part ) == 4 ) { // Script code. $ localeParts [ $ index ] = ucfirst ( $ part ) ; } else { // Country or variant code. $ localeParts [ $ index ] = strtoupper ( $ part ) ; } } return implode ( '-' , $ localeParts ) ; }
Canonicalizes the given locale.

Standardizes separators and capitalization, turning
a locale such as "sr_rs_latn" into "sr-RS-Latn".

@param string $locale The locale.

@return string The canonicalized locale.
Canonicalizes the given locale .