Module:LangToWiki

From Meta, a Wikimedia project coordination wiki
Module documentation
local p = {}

local Title = require('Module:Titlelib')

--[[
	Returns the Wikidata database identifier for the interwiki related to the
	language code given as first argument.
	
	@see T253387
]]
function p.wikidata(frame)
	local prefix = p.main( frame )
	local db_prefix = string.gsub(prefix, '-', '_')
	return db_prefix
end

--[[
	Returns the interwiki prefix matching with the requested language code as
	first argument.
	If no interwiki match with that language, the argument is returned as it is.

	Args:
		1: language code
]]
function p.main(frame)
	local prefix = Title.langToWiki(frame.args[1])
	if prefix then
		return prefix
	else
		return frame.args[1]
	end
end

return p