Module:R:map:ACD

From Wiktionary, the free dictionary
Jump to navigation Jump to search

This module implements the reference template {{R:map:ACD}}.


local export = {}

function export.main(frame)

	local args = require("Module:parameters").process(frame:getParent().args, {
		entry = { }, [1] = { alias_of = "entry" },
		id = { }, [2] = { alias_of = "id" },
		display = { }, alt = { alias_of = "display" },
		type = { },
	})

	local text

	if args.entry then

		local function format_numbers(str)
			return mw.ustring.gsub(str, "[1-9]$", {
				["1"] = "₁", ["2"] = "₂", ["3"] = "₃",
				["4"] = "₄", ["5"] = "₅", ["6"] = "₆",
				["7"] = "₇", ["8"] = "₈", ["9"] = "₉",
			})
		end

		local encoded_entry
		if (not args.id) then
			encoded_entry = mw.uri.encode(format_numbers(args.entry), "PATH")
		end

		if not args.type or args.type == "s" then
			text = "“[https://acd.clld.org/cognatesets"
				.. (args.id
					and "/" .. args.id
					or "?sSearch_1=" .. encoded_entry)
				.. " *"
		elseif args.type == "l" or args.type == "lo" then
			text = "loan “[https://acd.clld.org/"
				.. (args.id
					and "formsets/" .. args.id
					or "contributions/Loan?sSearch_0=" .. encoded_entry)
				.. " "
		elseif args.type == "r" then
			text = "root “[https://acd.clld.org/"
				.. (args.id
					and "formsets/Root-" .. args.id
					or "contributions/Root?sSearch_0=" .. encoded_entry)
				.. " *-"
		elseif args.type == "n" or args.type == "near" then
			text = "near cognates “[https://acd.clld.org/"
				.. (args.id
					and "formsets/Near-" .. args.id
					or "contributions/Near?sSearch_0=" .. encoded_entry)
				.. " "
		elseif args.type == "noise" then
			text = "chance resemblances “[https://acd.clld.org/"
				.. (args.id
					and "formsets/Noise-" .. args.id
					or "contributions/Noise?sSearch_0=" .. encoded_entry)
				.. " "
		end

		text = text .. format_numbers(args.display or args.entry) .. "]”, in the "

	else
		text = ""
	end

	return "Blust, Robert; Trussel, Stephen; et al. (2023) " .. text .. "CLDF dataset from <cite>The Austronesian Comparative Dictionary</cite> (2010–), [https://doi.org/10.5281/zenodo.7737547 →DOI]"

end

return export