Manual:Hooks/PageContentLanguage

From MediaWiki.org
Jump to navigation Jump to search
PageContentLanguage
Available from version 1.18.0 (r90742)
Allows changing the page content language and consequently all features depending on that (writing direction, LanguageConverter, ...).
Define function:
public static function onPageContentLanguage( Title $title, Language|string &$pageLang, $language ) { ... }
Attach hook:

In extension.json:

{
	"Hooks": {
		"PageContentLanguage": "MyExtensionHooks::onPageContentLanguage"
	}
}

For MediaWiki ≤1.25:

$wgHooks['PageContentLanguage'][] = 'MyExtensionHooks::onPageContentLanguage';
Called from: File(s): ContentHandler.php

For more information about attaching hooks, see Manual:Hooks.
For examples of extensions using this hook, see Category:PageContentLanguage extensions.

Details[edit]

  • $title: the Title object
  • &$pageLang: Language object or string; the page content language, either pass a Language object or a string (language code)
  • $language: Language or StubUserLang object; the user interface language

It was added in Title.php but is in content/ContentHandler.php since MediaWiki 1.21MediaWiki 1.21.

Example[edit]

For example, if you want to mark all pages in the namespace with index 200 (and its talk page 201) as being in French, use:

	static function onPageContentLanguage( $title, &$pageLang ) {
		if ( $title->getNamespace() === 200 || $title->getNamespace() === 201 ) {
			$pageLang = 'fr';
		}
		return true;
	}

See also[edit]