|Global object: $wgLang|
$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.
Often used Methods
This is not an exhaustive list, view class above to see a complete listing.
$wgLang->commaList( $list )
- delimit a list of strings according to the conventions of the user's language
- return the user's language code, for example "en"
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)
MediaWikiServicesto get the content language statically, e.g.
MediaWikiServices::getInstance()->getContentLanguage();(to read more about MediaWikiServices, see Dependency Injection)