Modul:Language

Z CZchan Wiki
Skočit na navigaci Skočit na vyhledávání

Dokumentaci tohoto modulu lze vytvořit na stránce Modul:Language/Dokumentace

require('strict')

local p = {}

local function getCode(args)
	return mw.text.trim(args[1] or '')
end

-- pozor, vrací prázdný string (který se chová jako true), ne nil
function p._getName(code)
	local data = mw.loadData('Modul:Languages/data')
	return data['overrides-names'][code] or mw.language.fetchLanguageName(code, 'cs')
end

function p._getNameVJazyce(code)
	local data = mw.loadData('Modul:Languages/data')
	return data['jak'][code]
end

function p._getLink(code)
	local data = mw.loadData('Modul:Languages/data')
	local target = data['overrides-links'][code]
	local label = p._getName(code)
	if label == '' then
		label = target
	end
	if not label then
		return nil
	end
	if target then
		return mw.ustring.format('[[%s|%s]]', target, label)
	else
		return mw.ustring.format('[[%s]]', label)
	end
end

function p._getLinkVJazyce(code)
	local data = mw.loadData('Modul:Languages/data')
	local label = p._getNameVJazyce(code)
	if not label then
		return nil
	end
	local n
	label, n = mw.ustring.gsub(label, '^(ve?) ', '%1 ', 1)
	local target = data['overrides-links'][code] or p._getName(code)
	if target ~= '' then
		return mw.ustring.format('[[%s|%s]]', target, label)
	else
		return label
	end
end

function p.getName(frame)
	local code = getCode(frame.args)
	return p._getName(code)
end

function p.getNameVJazyce(frame)
	local code = getCode(frame.args)
	return p._getNameVJazyce(code)
end

function p.getLink(frame)
	local code = getCode(frame.args)
	return p._getLink(code)
end

function p.getLinkVJazyce(frame)
	local code = getCode(frame.args)
	return p._getLinkVJazyce(code)
end

return p