public static function getFallback($locale): ?string
    {
        if (\function_exists('locale_parse')) {
            $localeSubTags = locale_parse($locale);
            if (1 === \count($localeSubTags)) {
                if (self::$defaultFallback === $localeSubTags['language']) {
                    return 'root';
                }

                // Don't return default fallback for "root", "meta" or others
                // Normal locales have two or three letters
                if (\strlen($locale) < 4) {
                    return self::$defaultFallback;
                }

                return null;
            }

            array_pop($localeSubTags);

            $fallback = locale_compose($localeSubTags);

            return false !== $fallback ? $fallback : null;
        }

        if (false !== $pos = strrpos($locale, '_')) {
            return substr($locale, 0, $pos);
        }

        if (false !== $pos = strrpos($locale, '-')) {
            return substr($locale, 0, $pos);
        }

        if (self::$defaultFallback === $locale) {
            return 'root';
        }

        // Don't return default fallback for "root", "meta" or others
        // Normal locales have two or three letters
        if (\strlen($locale) < 4) {
            return self::$defaultFallback;
        }

        return null;
    }
public static function getFallback($locale): ?string
    {
        if (\function_exists('locale_parse')) {
            $localeSubTags = locale_parse($locale);
            if (1 === \count($localeSubTags)) {
                if (self::$defaultFallback === $localeSubTags['language']) {
                    return 'root';
                }

                // Don't return default fallback for "root", "meta" or others
                // Normal locales have two or three letters
                if (\strlen($locale) < 4) {
                    return self::$defaultFallback;
                }

                return null;
            }

            array_pop($localeSubTags);

            $fallback = locale_compose($localeSubTags);

            return false !== $fallback ? $fallback : null;
        }

        if (false !== $pos = strrpos($locale, '_')) {
            return substr($locale, 0, $pos);
        }

        if (false !== $pos = strrpos($locale, '-')) {
            return substr($locale, 0, $pos);
        }

        if (self::$defaultFallback === $locale) {
            return 'root';
        }

        // Don't return default fallback for "root", "meta" or others
        // Normal locales have two or three letters
        if (\strlen($locale) < 4) {
            return self::$defaultFallback;
        }

        return null;
    }
public static function getFallback ( $ locale ) : ? string { if ( \ function_exists ( 'locale_parse' ) ) { $ localeSubTags = locale_parse ( $ locale ) ; if ( 1 === \ count ( $ localeSubTags ) ) { if ( self :: $ defaultFallback === $ localeSubTags [ 'language' ] ) { return 'root' ; } // Don't return default fallback for "root", "meta" or others // Normal locales have two or three letters if ( \ strlen ( $ locale ) < 4 ) { return self :: $ defaultFallback ; } return null ; } array_pop ( $ localeSubTags ) ; $ fallback = locale_compose ( $ localeSubTags ) ; return false !== $ fallback ? $ fallback : null ; } if ( false !== $ pos = strrpos ( $ locale , '_' ) ) { return substr ( $ locale , 0 , $ pos ) ; } if ( false !== $ pos = strrpos ( $ locale , '-' ) ) { return substr ( $ locale , 0 , $ pos ) ; } if ( self :: $ defaultFallback === $ locale ) { return 'root' ; } // Don't return default fallback for "root", "meta" or others // Normal locales have two or three letters if ( \ strlen ( $ locale ) < 4 ) { return self :: $ defaultFallback ; } return null ; }
Returns the fallback locale for a given locale.

For example, the fallback of "fr_FR" is "fr". The fallback of "fr" is
the default fallback locale configured with {@link setDefaultFallback()}.
The default fallback locale has no fallback.

@param string $locale The ICU locale code to find the fallback for

@return string|null The ICU locale code of the fallback locale, or null
if no fallback exists
Returns the fallback locale for a given locale .