Page MenuHomePhabricator

Wikibase namespace names cannot be translated (anymore?)
Open, Needs TriagePublic

Description

As a user primarily speaking a non-English language, I want to see translated names for the standard Wikibase namespaces (Item, Property).

Problem:
Wikibase has translated namespace names in repo/Wikibase.i18n.namespaces.php, but as far as I can tell, they are not used. Even if you set your wiki’s content language to a non-English language, you still get English names for the Item and Property namespaces.

This seems to be because Wikibase registers its namespaces through $wgExtraNamespaces (either in repo/config/Wikibase.example.php or in LocalSettings.php), whereas most extensions register them through the extension JSON file. In Language::getNamespaces(), the namespace names are combined like this:

$this->namespaceNames = $wgExtraNamespaces +
	$this->localisationCache->getItem( $this->mCode, 'namespaceNames' );
$this->namespaceNames += $validNamespaces;

Because the + operator for arrays doesn’t overwrite existing elements, this means that namespace names from $wgExtraNamespaces are never overwritten by names from the localisation cache.

Example:

Screenshots/mockups:
action=query&meta=siteinfo&siprop=namespaces on a local wiki with $wgLanguageCode = "es":
Screenshot_2020-08-10 Resultado de la API de MediaWiki - wiki1.png (711×415 px, 55 KB) Screenshot_2020-08-10 Resultado de la API de MediaWiki - wiki1-2.png (354×308 px, 27 KB)
Note that the namespaces Category (from core) and Module (from Scribunto) are translated, but Item is not, even though a translation for it is available («Elemento»).

LTR namespace name in an otherwise RTL interface:

Screenshot from 2020-08-10 18-23-41.png (161×736 px, 7 KB)

BDD
GIVEN
AND
WHEN
AND
THEN
AND

Acceptance criteria:

Open questions:

Event Timeline

The “anymore?” in the task title is because I assume this worked at some point, and maybe broke after most extensions had migrated their namespaces to extension.json, which still seems to work. (Wikibase doesn’t register its namespaces there because the item namespace, for instance, should not exist on Wikidata – we use the main namespace for items there.

Testing the ticket, I actually came to the same conclusion...

Technically speaking $namespaceNames in Wikibase.i18n.namespaces.php is not used anymore. I don't know what caused it but I'll check.

The translated names are still in the l10n cache, by the way, you can see them if you open e. g. cache/l10n_cache-es.cdb in a suitable editor (binary file with text parts; emacs and vim both work reasonably well).

Change 619332 had a related patch set uploaded (by Ladsgroup; owner: Ladsgroup):
[mediawiki/extensions/Wikibase@master] [WIP] First attempt to use extension.json namespace registration

https://gerrit.wikimedia.org/r/619332

I did a little bit of investigation on this, The reason for this is because Wikibase registers its namespaces through $wgExtraNamespaces global variable instead of doing it the right way (extension.json namespaces attribute) because values of that global variable (e.g. $wgExtraNamespaces[WB_NS_ITEM] = 'Item'; in Wikibase.example.php) take precedence over localized value as mediawiki thinks these are set by sysadmin and not the extension. For example if you reverse the order of array plus in this line, it would start working again: https://gerrit.wikimedia.org/g/mediawiki/core/+/1ed8b70ed8f741ae0cf34efcf573e577ce734401/languages/Language.php#591

Making namespace registered through extension.json would beautifully break installations hijacking core namespaces (Including but not limited to wikidata.org), the least they should do is to define WB_NS_ITEM with value of 0 (instead of not registering it) at all but they should not register the namespace directly, this very likely causes several breakages to be honest.

The tab name on top of the page doesn't come from the localized Item, specially for Wikidata as it registers them in main ns and not 120, It comes from nstab-main message: https://en.wikipedia.org/wiki/MediaWiki:Nstab-main (and https://wikidata.org/wiki/MediaWiki:Nstab-main). French is already set: https://www.wikidata.org/wiki/MediaWiki:Nstab-main/fr

TLDR: It's a mess.

Change 619332 abandoned by Lucas Werkmeister (WMDE):

[mediawiki/extensions/Wikibase@master] [WIP] First attempt to use extension.json namespace registration

Reason:

I think this has been superseded by I686e576e91, namespace registration now happens in a WikibaseRepo hook.

https://gerrit.wikimedia.org/r/619332