CakeFest 2024: The Official CakePHP Conference

Locale::getDisplayLanguage

locale_get_display_language

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

Locale::getDisplayLanguage -- locale_get_display_language入力ロケールの言語の表示名を、適切に地域化して返す

説明

オブジェクト指向型

public static Locale::getDisplayLanguage(string $locale, ?string $displayLocale = null): string|false

手続き型

locale_get_display_language(string $locale, ?string $displayLocale = null): string|false

入力ロケールの言語の表示名を、適切に地域化して返します。 null の場合はデフォルトのロケールを使用します。

パラメータ

locale

表示言語を返したいロケール。

displayLocale

オプションのフォーマットロケール。 言語名の表示に使用します。

戻り値

locale に対応する言語の表示名を、 displayLocale にあわせた形式で返します。 失敗した場合に false を返します

変更履歴

バージョン 説明
8.0.0 displayLocale は、nullable になりました。

例1 locale_get_display_language() の例

<?php
echo locale_get_display_language('sl-Latn-IT-nedis', 'en');
echo
";\n";
echo
locale_get_display_language('sl-Latn-IT-nedis', 'fr');
echo
";\n";
echo
locale_get_display_language('sl-Latn-IT-nedis', 'de');
?>

例2 オブジェクト指向の例

<?php
echo Locale::getDisplayLanguage('sl-Latn-IT-nedis', 'en');
echo
";\n";
echo
Locale::getDisplayLanguage('sl-Latn-IT-nedis', 'fr');
echo
";\n";
echo
Locale::getDisplayLanguage('sl-Latn-IT-nedis', 'de');
?>

上の例の出力は以下となります。

Slovenian;
slov\xc3\xa8ne;
Slowenisch

参考

add a note

User Contributed Notes 2 notes

up
1
jake at qzdesign dot co dot uk
4 years ago
If `$locale` is invalid, the return value is actually the value of `$locale`, not `NULL` or `FALSE` as you might expect.

(If `$in_locale` is invalid, but `$locale` is valid, the return value is the language name in the default locale.)
up
-10
heitor dot siller at gmail dot com
12 years ago
To display special characters correctly in a web browser, it's a good idea to decode the result data with utf8_decode:

<?php

echo utf8_decode(Locale::getDisplayLanguage('sl-Latn-IT-nedis', 'fr'));

echo
utf8_decode(Locale::getDisplayLanguage('sl-Latn-IT-nedis', 'pt-BR'));

?>
To Top