Consider the scenario, that I want to have a german wiki (wgContLang is de), and want to add an english text, that can be translated with the Translate extension. To make this work, I need to change the content model of the page I want to translate into english (instead of having the default german). For that I enable $wgPageLanguageUseDB and set it to true to be able to change the page language of a specific page to a different one.
Now, if I call Title::getPageLanguage() I would expect, that a language object is returned, which represents the DB language (en), instead of wgContLang (de). Unfortunately, the Translate extension still shows, that the page will be translated from de, not from en (db language).
I created a hook in another extension to recheck this:
public static function onPageContentLanguage( Title $title, Language &$pageLang, $userLang ) { var_dump($title->getPageLanguage()->getCode()); var_dump($pageLang->getCode()); }
The output is "en" and "de". That, btw., doesn't make much sense, because Title::getPageLanguage() is usually the function, which calls the hook (through ContentHandler::getPageLanguage()). I'm currently not sure, if this is a thing of my setup or not, will verify first.
Btw.: If I change the language in the hook:
public static function onPageContentLanguage( Title $title, Language &$pageLang, $userLang ) { $pageLang = wfGetLangObj( 'en' ); }
anything works fine.
Some further information with screenshots of the specific problem, that may help to understand the problem. The source page is "TestSections", which page language was set to german (using Special:PageLanguage). The content language is, by default, english:
The translateable page, when requested in the browser looks correctly:
But clicking on translate gives this result in the header (which, in fact, is false, the source language isn't en, it's de, saved in the db):
Requesting the english version of the page (TestSections/en) gives this confusing header:
Clicking on german (Deutsch) should redirect to TestSections (the base page, which has the page language german), but instead redirects to TestSections/de:
and says, that this is a translated version of the base page, which is (again) false :)
Outputting the source language of the base title (in PageTranslationHooks::languages()) shows the following:
while instead should say, that the source language is de (saved in the database), not en (default content language).
However, the problem does not occur, if you use getPageLanguage() in the title of the page you're currently viewing. WikiPage already requests the page_lang attribute and loads it correctly into the Title object.