Manual:$wgLang
Appearance
| グローバル オブジェクト: $wgLang | |
|---|---|
| 利用者の言語 | |
| クラス: | Language |
| 場所: | Language.php |
詳細
利用者言語オブジェクトは、利用者の個人設定で選択された言語のオブジェクトです。
2 つあるグローバルの言語オブジェクトのうちの 1 つであり、もう一方は $wgContLang (1.36 で除去) です。
詳細情報はページ Manual:言語 を参照してください。
$wgLang is initialized towards the end of setup; some hooks are called earlier than that and should avoid using it.
When in doubt use $wgUser->isSafeToLoad() to check.
よく使用されるメソッド
これは完全な一覧ではありません。完全な一覧を見るためには、上のクラスを参照してください。
$wgLang->commaList( $list )- delimit a list of strings according to the conventions of the user's language
$wgLang->getCode()- 利用者の言語コードを返します。例: "ja"
推奨される代替
It is best that new code avoids using global variables when alternatives exist. In the case of $wgLang, two alternatives exist and can be used:
- Use an instance of
Contextclass to get the language used in that context, e.g.$contextSource->getLanguage(). (see also: Manual:RequestContext.php#Accessors) - Use
MediaWikiServicesto get the content language statically, e.g.MediaWikiServices::getInstance()->getContentLanguage();. (To read more about MediaWikiServices, see Dependency Injection)