Module:Wikt-lang

This is an old revision of this page, as edited by Erutuon (talk | contribs) at 05:16, 1 October 2016 (add languageSpan and lang function and rewrite wikt). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

--[[ Name is the "canonical name" used on Wiktionary. Article is the Wikipedia article. Script is the ISO 15924 code. ]]

data = {
	["ar"] = {
		["name"] = "Arabic",
		["article"] = "Arabic language",
		["script"] = "Arab",
	},
	["en"] = {
		["name"] = "English",
		["article"] = "English language",
		["script"] = "Latn",
	},
	["grc"] = {
		["name"] = "Ancient Greek",
		["article"] = "Ancient Greek",
		["script"] = "Grek",
	},
	["ru"] = {
		["name"] = "Russian",
		["article"] = "Russian language",
		["script"] = "Cyrl",
	},
}

--[[

	[""] = {
		["name"] = "",
		["article"] = "",
		["script"] = "",
	},

]]

f = {}

local function strip(word)
	local replacements = {
		["́"] = ""
		}
	return string.gsub(word, "́", "")
end

local function languageSpan(languageCode, text)
	return "<span lang=\"" .. languageCode .. "\" xml:lang=\"" .. languageCode .. "\">" .. text .. "</span>"
end

function f.lang(frame)
	return languageSpan(frame.args[1], frame.args[2])
end

function f.wikt(frame)
	local languageCode = frame.args[1]
	local word1 = frame.args[2]
	local word2 = frame.args[3]
	local languageData = data[languageCode]
	local languageName = languageData["name"]
	local entry = ""
	if languageData == nil then
		error("Language code is not recognized")
	end
	if languageCode then
		if word2 and word1 then
			entry = strip(word1)
			linkText = word2
		elseif word1 then
			entry = strip(word1)
			linkText = word1
		else
			error("Please provide a word in the second parameter")
		end
	else
		error("Please provde a language code in the first parameter")
	end
	return languageSpan(languageCode, "[[wikt:" .. entry .. "#" .. languageName .. "|" .. linkText .. "]]")
end

return f