Manual:$wgLang
Appearance
| Objeto global: $wgLang | |
|---|---|
| Idioma do usuário | |
| Classe: | Language |
| Localizado em: | Language.php |
Detalhes
O objeto idioma do usuário é o objeto do idioma selecionado nas preferências do usuário.
É um dos dois objetos de linguagem global, sendo o outro $wgContLang (removido na 1.36).
Veja a página Manual:Idiomas para mais informações.
$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.
Métodos utilizados frequentemente
Esta não é uma lista exaustiva, visualize a classe acima para ver a lista completa.
$wgLang->commaList( $list )- delimita uma lista de strings de acordo com as convenções do idioma do usuário
$wgLang->getCode()- retorna o código do idioma do usuário, por exemplo, "pt-br"
Recommended alternative
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)