Page MenuHomePhabricator

Create a Lua convenience functions for conversion betweem language code and project and sitelink code
Open, Needs TriagePublicFeature

Description

There are 900-1000 sitelink codes at the moment (like "be_x_oldwiki") and each is associated with a language code and project (like "be-tarask" and "Wikipedia"). Many Lua tools are parsing sitelinks to get language code and project or creating sitelinks based on users language and project, and many of them have to hardwire a lot of confusing special cases. It would be nice to have 2 convenience functions with "official" conversion between sitelink ID (same as used by mw.wikibase.getSitelink) and language codes (same as used by Lua Language_library).

Some relevant links:

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

YES, PLEASE! Wikidata Infobox uses this function to convert a language code into a site ID:

local function databaseId( langcode )
	local exceptions = {
		['be-tarask'] = 'be_x_old',     -- Belarusian (Taraškievica orthography)
		['bho']       = 'bh',           -- Bhojpuri
		['cbk-zam']   = 'cbk_zam',      -- Chavacano de Zamboanga
		['gsw']       = 'als',          -- Alemannic
		['ike']       = 'iu',           -- Inuktitut
		['lzh']       = 'zh_classical', -- Classical Chinese
		['map-bms']   = 'map_bms',      -- Basa Banyumasan
		['nan']       = 'zh_min_nan',   -- Min Nan Chinese
		['nb']        = 'no',           -- Norwegian Bokmål
		['nds-nl']    = 'nds_nl',       -- Low Saxon
		['mo']        = 'ro',           -- Moldaawisk
		['roa-tara']  = 'roa_tara',     -- Tarantino
		['rup']       = 'roa_rup',      -- Aromanian
		['sgs']       = 'bat_smg',      -- Samogitian
		['vro']       = 'fiu_vro',      -- Võro
		['yue']       = 'zh_yue',       -- Cantonese
	}

	local exception = exceptions[langcode]
	if exception then return exception end

	return langcode:gsub("-.*", "") -- delete everything after hyphen
end

I painstakingly compiled the list of exceptions from a variety of sources, and I'm not sure whether the list is comprehensive. This issue is annoying module writers since at least 2018.

Tacsipacsi changed the subtype of this task from "Task" to "Feature Request".
Tacsipacsi subscribed.

Special:SiteMatrix is provided by SiteMatrix, not Wikibase, so this code may have a better place there. (Although SiteMatrix has no Lua support yet, so it’d require a bit more setup.)