Podręcznik:$wgLang

This page is a translated version of the page Manual:$wgLang and the translation is 56% complete.

Szczegóły

Obiekt języka użytkownika jest obiektem języka wybranym w preferencjach użytkownika. Jest to jeden z dwóch globalnych obiektów języka, drugi to $wgContLang (usunięto w 1.36). Zobacz stronę Podręcznik:Język , aby uzyskać więcej informacji.

$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.


Często używane metody

To nie jest wyczerpująca lista, zobacz opis klasy wspomnianej powyżej, aby zobaczyć kompletną listę.

$wgLang->commaList( $list )
tworzy listę ciągów znaków oddzielanych separatorem ustalonym w konwencji języka użytkownika
$wgLang->getCode()
zwraca kod języka użytkownika, np. "pl"

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 Context class to get the language used in that context, e.g. $contextSource->getLanguage(). (see also: Manual:RequestContext.php#Accessors)
  • Use MediaWikiServices to get the content language statically, e.g. MediaWikiServices::getInstance()->getContentLanguage();. (To read more about MediaWikiServices, see Dependency Injection )