Module:R:sq:Bardhi:1635

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

This module implements the reference template {{R:sq:Bardhi:1635}}.


local export = {}

function export.main(frame)

	local args = require("Module:parameters").process(frame:getParent().args, {
		[1] = { list = true, allow_holes = true },
		it = { list = true },
		page = { list = true }, pages = { list = true, alias_of = "page" },
		passage = { list = true, allow_holes = true },
	})

	local terms = args[1] or {}
	local term_it = args.it or {}
	local pages = args.page or {}
	local passages = args.passage or {}

	local expand_args = {
		worklang = "la,sq",
		title = "Dictionarium Latino Epiroticum",
		first = "Frang", last = "Bardhi", authorlink = "Frang Bardhi",
		year = "1635",
	}

	local function get_pageurl(page)
		return "https://books.google.com/?id=PJP7gP1p-JAC&pg=PA" .. string.match(page, "^%d+")
	end

	local additional = ""

	if #pages == 0 then
		expand_args.url = "https://books.google.com/?id=PJP7gP1p-JAC"
	else
		local format_link = require("Module:links").language_link
		local get_lang = require("Module:languages").getByCode
		local function get_passage(index)
			if passages[index] then return passages[index] end
			if not terms[index * 2 - 1] or not terms[index * 2] then
				error("Content must be given for each page!")
			end
			local passage = format_link { term = terms[index * 2 - 1], lang = get_lang("la") }
			if term_it[index] then
				passage = passage .. ", " .. format_link { term = term_it[index], lang = get_lang("it") }
			end
			return passage .. " — " .. terms[index * 2]
		end
		if #pages == 1 then
			expand_args.passage = get_passage(1)
			expand_args.page = pages[1]
			expand_args.pageurl = get_pageurl(pages[1])
		else
			additional = ":"
			for page_index, page in ipairs(pages) do
				additional = additional
					.. "\n** [" .. get_pageurl(page) .. " page " .. page .. "]: “"
					.. get_passage(page_index) .. "”"
			end
		end
	end

	return frame:expandTemplate { title = "cite-book", args = expand_args } .. additional

end

return export