Open main menu

Manual:Hooks/PageContentLanguage

< Manual:Hooks
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, mixed &$pageLang, Language|StubUserLang $userLang ) { ... }
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.

DetailsEdit

  • $title: the Title object
  • &$pageLang: Language of the page. You should assign a Language object to it, but because other hooks can modify the value, the type can be anything, like a string.
  • $userLang: Language or StubUserLang object; the user interface language

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

ExampleEdit

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 $title, &$pageLang, $userLang ) {
		if ( $title->inNamespaces( 200, 201 ) ) {
			$pageLang = Language::factory( 'fr' );
		}
	}

See alsoEdit