Manual:Hooks/PageContentLanguage

PageContentLanguage
Available from version 1.18.0 (r90742, codereview)
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": "MediaWiki\\Extension\\MyExtension\\Hooks::onPageContentLanguage"
	}
}
Called from: File(s): ContentHandler.php
Interface: PageContentLanguageHook.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 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 .

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

See also

edit