public static function sanitizeLanguage($locale, $default = null)
    {
        if ($locale instanceof Locale) {
            return $locale->getLanguage();
        }

        if ($default) {
            $default = Locale::sanitizeLanguage($default, null);
        }

        $locale = (string) $locale;
        $locale = trim($locale);

        if (!$locale || !preg_match("/^(?<language>[a-z]{2})/ui", $locale, $found)) {
            return $default;
        }

        return Text::toLower($found['language']);
    }
public static function sanitizeLanguage($locale, $default = null)
    {
        if ($locale instanceof Locale) {
            return $locale->getLanguage();
        }

        if ($default) {
            $default = Locale::sanitizeLanguage($default, null);
        }

        $locale = (string) $locale;
        $locale = trim($locale);

        if (!$locale || !preg_match("/^(?<language>[a-z]{2})/ui", $locale, $found)) {
            return $default;
        }

        return Text::toLower($found['language']);
    }
public static function sanitizeLanguage ( $ locale , $ default = null ) { if ( $ locale instanceof Locale ) { return $ locale -> getLanguage ( ) ; } if ( $ default ) { $ default = Locale :: sanitizeLanguage ( $ default , null ) ; } $ locale = ( string ) $ locale ; $ locale = trim ( $ locale ) ; if ( ! $ locale || ! preg_match ( "/^(?<language>[a-z]{2})/ui" , $ locale , $ found ) ) { return $ default ; } return Text :: toLower ( $ found [ 'language' ] ) ; }
Sanitize given language from locale.

Must be a simple locale without code set, currency or similar (e. g. "de_DE" or "de-de" or "de").

@param string|Locale $locale
@param string|Locale $default [optional] The default locale to return if $locale is invalid

@return null|string
Sanitize given language from locale .