public function localeToLanguage(string $locale): string
    {
        if (empty($locale)) {
            throw new InvalidArgumentException("Locale must be a non-emptystring.");
        }

        // Truncate all, starting with underscore, at, or dot
        $result = (string)preg_replace('/(_|@|\.).*$/', '', strtolower($locale));
        // Convert to lowercase for consistency
        $result = strtolower($result);

        return $result;
    }
public function localeToLanguage(string $locale): string
    {
        if (empty($locale)) {
            throw new InvalidArgumentException("Locale must be a non-emptystring.");
        }

        // Truncate all, starting with underscore, at, or dot
        $result = (string)preg_replace('/(_|@|\.).*$/', '', strtolower($locale));
        // Convert to lowercase for consistency
        $result = strtolower($result);

        return $result;
    }
public function localeToLanguage ( string $ locale ) : string { if ( empty ( $ locale ) ) { throw new InvalidArgumentException ( "Locale must be a non-emptystring." ) ; } // Truncate all, starting with underscore, at, or dot $ result = ( string ) preg_replace ( '/(_|@|\.).*$/' , '' , strtolower ( $ locale ) ) ; // Convert to lowercase for consistency $ result = strtolower ( $ result ) ; return $ result ; }
Convert locale to language

On Linux, have a look at /usr/share/locale for the
list of possible locales and locale formats.

@throws \InvalidArgumentException when locale is not a string
@param string $locale Locale string (example: ru_RU.KOI8-R)
@return string Language (example: ru)
Convert locale to language