CakeFest 2024: The Official CakePHP Conference

Locale::getPrimaryLanguage

locale_get_primary_language

(PHP 5 >= 5.3.0, PHP 7, PHP 8, PECL intl >= 1.0.0)

Locale::getPrimaryLanguage -- locale_get_primary_languageObtener el lenguaje principal de la configuración regional de entrada

Descripción

Estilo orientado a objetos

public static Locale::getPrimaryLanguage(string $locale): string

Estilo por procedimientos

locale_get_primary_language(string $locale): string

Obtiene el lenguaje principal de la configuración regional de entrada

Parámetros

locale

La configuración regional desde la que extraer el código del lenguaje principal

Valores devueltos

El código de lenguaje asociado con el lenguaje o null en caso de error.

Ejemplos

Ejemplo #1 Ejemplo de locale_get_primary_language()

<?php
echo locale_get_primary_language('zh-Hant');
?>

Ejemplo #2 Ejemplo orientado a objetos

<?php
echo Locale::getPrimaryLanguage('zh-Hant');
?>

El resultado del ejemplo sería:

zh

Ver también

add a note

User Contributed Notes 1 note

up
16
Mahn
8 years ago
The behaviour when a falsy value is passed as the $locale is undocumented, but it appears that it returns the primary language of the default system language. In my case:

Locale::getPrimaryLanguage(null);

Returns 'en'. So make sure to test $locale before passing it to the method.
To Top