Page MenuHomePhabricator

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


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

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.


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)


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

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:

Making namespace registered through extension.json would beautifully break installations hijacking core namespaces (Including but not limited to, 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: (and French is already set:

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


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