Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getNamespaceBaseLanguage should be replaced with getPageLanguage #3

Open
DankRank opened this issue Dec 24, 2019 · 2 comments
Open

Comments

@DankRank
Copy link
Member

Similar code exists in our Translate fork, but upstream now uses getPageLanguage, so it makes more sense to just set up a PageContentLanguage hook in our LocalSettings like so:

$wgHooks['PageContentLanguage'][] = function( Title $title, &$pageLang, $userLang ) {
    global $wgLanguageCode;
    $pageLang = Language::factory( $title->getNamespace() !== NS_MAIN ? $wgLanguageCode : 'ja' );
}

Should probably not run this hook when Translate's own hook is activated (in_array( $namespace, $wgTranslateMessageNamespaces );)

@DankRank DankRank added this to the mediawiki upgrade milestone Dec 24, 2019
@DankRank
Copy link
Member Author

Maybe that hook could even be

$wgHooks['PageContentLanguage'][] = function( Title $title, &$pageLang, $userLang ) {
    if ( $title->getNamespace() === NS_MAIN ) {
        $pageLang = Language::factory( 'ja' );
    }
}

@DankRank
Copy link
Member Author

Translate actually has two PageContentLanguage hooks. The one I mentioned before is for NS_TRANSLATIONS (also used by default on NS_MEDIAWIKI and wfAddNamespace namespaces, but not on our wiki).
There's a second hook for page translation, which handles translation subpages in NS_MAIN and others. Sadly the order in which hooks run is kind of undefined (the docs say wgHooks run before the 1.25 extensions.json hooks, but they also tell to not rely on it), which means we can't use the hooks above, because they may override the Translate hook.

We do actually modify the said hook with something like the above, so currently everything is already set up corretly. (source)
Do note that it's filtered with isSourcePage, meaning that a page that is not marked for translation is considered English. We could actually use that to make the hook order-independent (when we remove that patch from Translate, that is).

$wgHooks['PageContentLanguage'][] = function( Title $title, &$pageLang, $userLang ) {
    if ( $title->getNamespace() === NS_MAIN and TranslatablePage::isSourcePage( $title ) ) {
        $pageLang = Language::factory( 'ja' );
    }
}

However, MW 1.24+ has a better solution: you can simply go to Special:PageLanguage, and change the page content language of a page (has to be enabled with $wgPageLanguageUseDB = true;).

So it looks like we can replace all the NS_MAIN ? 'ja' : 'en' hacks with page content lang in both TPC and Translate.

By the way, this is how we would migrate on MW 1.24

UPDATE page INNER JOIN revtag on rt_page = page_id AND rt_revision = page_latest
SET page_lang = 'ja'
WHERE page_namespace = 0 AND rt_type IN ('tp:mark', 'tp:tag');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant