Module:cognates: Difference between revisions

From Laenkea
Jump to navigation Jump to search
No edit summary
No edit summary
Line 4: Line 4:
local m_inline = require("Module:inline")
local m_inline = require("Module:inline")
local m_languages = require("Module:languages")
local m_languages = require("Module:languages")
local m_links = require("Module:links")


function export.show(frame)
function export.show(frame)
Line 19: Line 18:
local term, data = m_inline.parse(entry)
local term, data = m_inline.parse(entry)
local cat = ""
local cat = ""
lang = m_languages.get_by_code(lang)
data[1], data[2] = lang, term
data["language"] = lang
local link = frame:expandTemplate{title = "m+", args = data}
data["term"] = term
data["showlanguage"] = true
local link = m_links.full_link(data, "term")
if nat then
if nat then
link = link .. "[[Category:" .. nat.name .. " terms with " .. lang.name .. " cognates]]"
link = link .. "[[Category:" .. nat.name .. " terms with " .. lang.name .. " cognates]]"
Line 30: Line 26:
elseif params[lang] ~= nil then --check for parameters
elseif params[lang] ~= nil then --check for parameters
params[lang] = true
params[lang] = true
else
error("[" .. lang .. "] is not a valid language code or parameter")
end
end
end
end

Revision as of 22:23, 6 August 2024

Underlies {{cognates}}.


local export = {}
local getArgs = require('Module:Arguments').getArgs

local m_inline = require("Module:inline")
local m_languages = require("Module:languages")

function export.show(frame)
	local args = getArgs(frame)
	local links = {}
	local nat = m_languages.find_by_code(args[1] or "") ~= nil and m_languages.get_by_code(args[1])
	local params = {
		nocap = false,
	}
	
	for lang, entry in pairs(args) do
		if type(lang) == "string" then
			if m_languages.find_by_code(lang) then
				local term, data = m_inline.parse(entry)
				local cat = ""
				data[1], data[2] = lang, term
				local link = frame:expandTemplate{title = "m+", args = data}
				if nat then
					link = link .. "[[Category:" .. nat.name .. " terms with " .. lang.name .. " cognates]]"
				end
				table.insert(links, link)
			elseif params[lang] ~= nil then --check for parameters
				params[lang] = true
			else
				error("[" .. lang .. "] is not a valid language code or parameter")
			end
		end
	end
	
	local text = ((params.nocap and "c") or "C") .. "ognate with "
	
	for i, link in ipairs(links) do
		if i > 1 then
			if links[i + 1] then
				text = text .. ", "
			else
				text = text .. " and "	
			end
		end
		text = text .. link	
	end
	
	return text
end

return export

--[[
Debug console test string:
=p.show(mw.getCurrentFrame():newChild{title="whatever",args={["rad"]="vas", ["lfv"] = "vat"}})
]]