Differenze tra le versioni di "Modulo:Headword/templates"

Da Dialetto Metaurense.
Riga 1: Riga 1:
 
local export = {}
 
local export = {}
  
 +
-- Part of speech types that should not be pluralized.
 
local invariable = {
 
local invariable = {
 
["cmavo"] = true,
 
["cmavo"] = true,
Riga 16: Riga 17:
 
["rafsi"] = true,
 
["rafsi"] = true,
 
["romaji"] = true,
 
["romaji"] = true,
 +
}
 +
 +
local params = {
 +
[1] = {required = true},
 +
["sc"] = {},
 +
["cat sc"] = {},
 +
["sort"] = {},
 +
 +
[2] = {},
 +
["cat2"] = {},
 +
["cat3"] = {},
 +
 +
["head"] = {},
 +
["head2"] = {},
 +
["head3"] = {},
 +
["head4"] = {},
 +
["head5"] = {},
 +
 +
["tr"] = {},
 +
["tr2"] = {},
 +
["tr3"] = {},
 +
["tr4"] = {},
 +
["tr5"] = {},
 +
 +
["g"] = {},
 +
["g2"] = {},
 +
["g3"] = {},
 +
["g4"] = {},
 +
["g5"] = {},
 +
 +
[3]  = {allow_empty = true}, [4]  = {}, ["f1accel"] = {}, ["f1request"] = {}, ["f1alt"] = {}, ["f1sc"] = {}, ["f1id"] = {}, ["f1tr"] = {}, ["f1g"] = {}, ["f1qual"] = {}, ["f1nolink"] = {type = "boolean"}, ["f1lang"] = {},
 +
[5]  = {allow_empty = true}, [6]  = {}, ["f2accel"] = {}, ["f2request"] = {}, ["f2alt"] = {}, ["f2sc"] = {}, ["f2id"] = {}, ["f2tr"] = {}, ["f2g"] = {}, ["f2qual"] = {}, ["f2nolink"] = {type = "boolean"}, ["f2lang"] = {},
 +
[7]  = {allow_empty = true}, [8]  = {}, ["f3accel"] = {}, ["f3request"] = {}, ["f3alt"] = {}, ["f3sc"] = {}, ["f3id"] = {}, ["f3tr"] = {}, ["f3g"] = {}, ["f3qual"] = {}, ["f3nolink"] = {type = "boolean"}, ["f3lang"] = {},
 +
[9]  = {allow_empty = true}, [10] = {}, ["f4accel"] = {}, ["f4request"] = {}, ["f4alt"] = {}, ["f4sc"] = {}, ["f4id"] = {}, ["f4tr"] = {}, ["f4g"] = {}, ["f4qual"] = {}, ["f4nolink"] = {type = "boolean"}, ["f4lang"] = {},
 +
[11] = {allow_empty = true}, [12] = {}, ["f5accel"] = {}, ["f5request"] = {}, ["f5alt"] = {}, ["f5sc"] = {}, ["f5id"] = {}, ["f5tr"] = {}, ["f5g"] = {}, ["f5qual"] = {}, ["f5nolink"] = {type = "boolean"}, ["f5lang"] = {},
 +
[13] = {allow_empty = true}, [14] = {}, ["f6accel"] = {}, ["f6request"] = {}, ["f6alt"] = {}, ["f6sc"] = {}, ["f6id"] = {}, ["f6tr"] = {}, ["f6g"] = {}, ["f6qual"] = {}, ["f6nolink"] = {type = "boolean"}, ["f6lang"] = {},
 +
[15] = {allow_empty = true}, [16] = {}, ["f7accel"] = {}, ["f7request"] = {}, ["f7alt"] = {}, ["f7sc"] = {}, ["f7id"] = {}, ["f7tr"] = {}, ["f7g"] = {}, ["f7qual"] = {}, ["f7nolink"] = {type = "boolean"}, ["f7lang"] = {},
 +
[17] = {allow_empty = true}, [18] = {}, ["f8accel"] = {}, ["f8request"] = {}, ["f8alt"] = {}, ["f8sc"] = {}, ["f8id"] = {}, ["f8tr"] = {}, ["f8g"] = {}, ["f8qual"] = {}, ["f8nolink"] = {type = "boolean"}, ["f8lang"] = {},
 +
[19] = {allow_empty = true}, [20] = {}, ["f9accel"] = {}, ["f9request"] = {}, ["f9alt"] = {}, ["f9sc"] = {}, ["f9id"] = {}, ["f9tr"] = {}, ["f9g"] = {}, ["f9qual"] = {}, ["f9nolink"] = {type = "boolean"}, ["f9lang"] = {},
 
}
 
}
  
 
function export.head_t(frame)
 
function export.head_t(frame)
−
local args = frame:getParent().args
+
local args = require("Module:parameters").process(frame:getParent().args, params)
 
 
 
-- Get language and script information
 
-- Get language and script information
−
local lang = args[1] or (mw.title.getCurrentTitle().nsText == "Template" and "und") or error("Language code has not been specified. Please pass parameter 1 to the template.")
+
local lang = args[1] or "und"
−
local sc = args["sc"] or ""; if sc == "" then sc = nil end
+
local sc = args["sc"]
−
local cat_sc = args["cat sc"] or ""; if cat_sc == "" then cat_sc = nil end
+
local cat_sc = args["cat sc"]
 
lang = require("Module:languages").getByCode(lang) or error("The language code \"" .. lang .. "\" is not valid.")
 
lang = require("Module:languages").getByCode(lang) or error("The language code \"" .. lang .. "\" is not valid.")
 
 
Riga 35: Riga 75:
 
 
 
-- Gather basic parameters
 
-- Gather basic parameters
−
local sort_key = args["sort"]; if sort_key == "" then sort_key = nil end
+
local sort_key = args["sort"]
−
local pos = args[2]; if pos == "" then pos = nil end
+
local pos = args[2]
−
local cat2 = args["cat2"]; if cat2 == "" then cat2 = nil end
+
local cat2 = args["cat2"]
−
local cat3 = args["cat3"]; if cat3 == "" then cat3 = nil end
+
local cat3 = args["cat3"]
 
 
 
-- Gather headwords and transliterations
 
-- Gather headwords and transliterations
Riga 44: Riga 84:
 
local translits = {}
 
local translits = {}
 
local head = args["head"] or ""
 
local head = args["head"] or ""
−
local translit = args["tr"]; if translit == "" then translit = nil end
+
local translit = args["tr"]
 
local i = 1
 
local i = 1
 
 
Riga 54: Riga 94:
 
 
 
i = i + 1
 
i = i + 1
−
head = args["head" .. i]; if head == "" then head = nil end
+
head = args["head" .. i]
−
translit = args["tr" .. i]; if translit == "" then translit = nil end
+
translit = args["tr" .. i]
 
end
 
end
 
 
Riga 61: Riga 101:
 
-- Iterate over all gn parameters (g2, g3 and so on) until one is empty
 
-- Iterate over all gn parameters (g2, g3 and so on) until one is empty
 
local genders = {}
 
local genders = {}
−
local g = args["g"]; if g == "" then g = nil end
+
local g = args["g"]
 
local i = 2
 
local i = 2
 
 
 
while g do
 
while g do
 
table.insert(genders, g)
 
table.insert(genders, g)
−
g = args["g" .. i]; if g == "" then g = nil end
+
g = args["g" .. i]
 
i = i + 1
 
i = i + 1
 
end
 
end
Riga 75: Riga 115:
 
local i = 1
 
local i = 1
 
local label = args[i * 2 + 1]
 
local label = args[i * 2 + 1]
−
local accel = args["f" .. i .. "accel"]; if accel == "" then accel = nil end
+
local accel = args["f" .. i .. "accel"]
−
local request = args["f" .. i .. "request"]; if request == "" then request = nil end
+
local request = args["f" .. i .. "request"]
 
local parts = {label = label, accel = accel, request = request}
 
local parts = {label = label, accel = accel, request = request}
 
 
Riga 82: Riga 122:
 
 
 
while label do
 
while label do
−
local term = args[i * 2 + 2]; if term == "" then term = nil end
+
local term = args[i * 2 + 2]
−
local alt = args["f" .. i .. "alt"]; if alt == "" then alt = nil end
+
local alt = args["f" .. i .. "alt"]
−
local sc = args["f" .. i .. "sc"]; if sc == "" then sc = nil end
+
local sc = args["f" .. i .. "sc"]
−
local id = args["f" .. i .. "id"]; if id == "" then id = nil end
+
local id = args["f" .. i .. "id"]
−
local translit = args["f" .. i .. "tr"]; if translit == "" then translit = nil end
+
local translit = args["f" .. i .. "tr"]
−
local gender = args["f" .. i .. "g"]; if gender == "" then gender = nil end
+
local gender = args["f" .. i .. "g"]
−
local qualifier = args["f" .. i .. "qual"]; if qualifier == "" then qualifier = nil end
+
local qualifier = args["f" .. i .. "qual"]
−
local nolink = args["f" .. i .. "nolink"]; if nolink == "" then nolink = nil end
+
local nolink = args["f" .. i .. "nolink"]
−
local lang = args["f" .. i .. "lang"]; if lang == "" then lang = nil end
+
local lang = args["f" .. i .. "lang"]
 
 
 
if lang ~= nil then
 
if lang ~= nil then
Riga 107: Riga 147:
 
i = i + 1
 
i = i + 1
 
label = args[i * 2 + 1]
 
label = args[i * 2 + 1]
−
accel = args["f" .. i .. "accel"]; if accel == "" then accel = nil end
+
accel = args["f" .. i .. "accel"]
−
request = args["f" .. i .. "request"]; if request == "" then request = nil end
+
request = args["f" .. i .. "request"]
 
 
 
-- If the next label is not "or" then insert the previous one and create a new one.
 
-- If the next label is not "or" then insert the previous one and create a new one.

Versione delle 13:44, 6 mag 2015

La documentazione per questo modulo può essere creata in Modulo:Headword/templates/man

local export = {}

-- Part of speech types that should not be pluralized.
local invariable = {
	["cmavo"] = true,
	["cmene"] = true,
	["fu'ivla"] = true,
	["gismu"] = true,
	["Han tu"] = true,
	["hanzi"] = true,
	["hanja"] = true,
	["jyutping"] = true,
	["kanji"] = true,
	["lujvo"] = true,
	["phrasebook"] = true,
	["pinyin"] = true,
	["rafsi"] = true,
	["romaji"] = true,
}

local params = {
	[1] = {required = true},
	["sc"] = {},
	["cat sc"] = {},
	["sort"] = {},
	
	[2] = {},
	["cat2"] = {},
	["cat3"] = {},
	
	["head"] = {},
	["head2"] = {},
	["head3"] = {},
	["head4"] = {},
	["head5"] = {},
	
	["tr"] = {},
	["tr2"] = {},
	["tr3"] = {},
	["tr4"] = {},
	["tr5"] = {},
	
	["g"] = {},
	["g2"] = {},
	["g3"] = {},
	["g4"] = {},
	["g5"] = {},
	
	[3]  = {allow_empty = true}, [4]  = {}, ["f1accel"] = {}, ["f1request"] = {}, ["f1alt"] = {}, ["f1sc"] = {}, ["f1id"] = {}, ["f1tr"] = {}, ["f1g"] = {}, ["f1qual"] = {}, ["f1nolink"] = {type = "boolean"}, ["f1lang"] = {},
	[5]  = {allow_empty = true}, [6]  = {}, ["f2accel"] = {}, ["f2request"] = {}, ["f2alt"] = {}, ["f2sc"] = {}, ["f2id"] = {}, ["f2tr"] = {}, ["f2g"] = {}, ["f2qual"] = {}, ["f2nolink"] = {type = "boolean"}, ["f2lang"] = {},
	[7]  = {allow_empty = true}, [8]  = {}, ["f3accel"] = {}, ["f3request"] = {}, ["f3alt"] = {}, ["f3sc"] = {}, ["f3id"] = {}, ["f3tr"] = {}, ["f3g"] = {}, ["f3qual"] = {}, ["f3nolink"] = {type = "boolean"}, ["f3lang"] = {},
	[9]  = {allow_empty = true}, [10] = {}, ["f4accel"] = {}, ["f4request"] = {}, ["f4alt"] = {}, ["f4sc"] = {}, ["f4id"] = {}, ["f4tr"] = {}, ["f4g"] = {}, ["f4qual"] = {}, ["f4nolink"] = {type = "boolean"}, ["f4lang"] = {},
	[11] = {allow_empty = true}, [12] = {}, ["f5accel"] = {}, ["f5request"] = {}, ["f5alt"] = {}, ["f5sc"] = {}, ["f5id"] = {}, ["f5tr"] = {}, ["f5g"] = {}, ["f5qual"] = {}, ["f5nolink"] = {type = "boolean"}, ["f5lang"] = {},
	[13] = {allow_empty = true}, [14] = {}, ["f6accel"] = {}, ["f6request"] = {}, ["f6alt"] = {}, ["f6sc"] = {}, ["f6id"] = {}, ["f6tr"] = {}, ["f6g"] = {}, ["f6qual"] = {}, ["f6nolink"] = {type = "boolean"}, ["f6lang"] = {},
	[15] = {allow_empty = true}, [16] = {}, ["f7accel"] = {}, ["f7request"] = {}, ["f7alt"] = {}, ["f7sc"] = {}, ["f7id"] = {}, ["f7tr"] = {}, ["f7g"] = {}, ["f7qual"] = {}, ["f7nolink"] = {type = "boolean"}, ["f7lang"] = {},
	[17] = {allow_empty = true}, [18] = {}, ["f8accel"] = {}, ["f8request"] = {}, ["f8alt"] = {}, ["f8sc"] = {}, ["f8id"] = {}, ["f8tr"] = {}, ["f8g"] = {}, ["f8qual"] = {}, ["f8nolink"] = {type = "boolean"}, ["f8lang"] = {},
	[19] = {allow_empty = true}, [20] = {}, ["f9accel"] = {}, ["f9request"] = {}, ["f9alt"] = {}, ["f9sc"] = {}, ["f9id"] = {}, ["f9tr"] = {}, ["f9g"] = {}, ["f9qual"] = {}, ["f9nolink"] = {type = "boolean"}, ["f9lang"] = {},
}

function export.head_t(frame)
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	-- Get language and script information
	local lang = args[1] or "und"
	local sc = args["sc"]
	local cat_sc = args["cat sc"]
	lang = require("Module:languages").getByCode(lang) or error("The language code \"" .. lang .. "\" is not valid.")
	
	if cat_sc then
		cat_sc = (cat_sc and (require("Module:scripts").getByCode(cat_sc) or error("The script code \"" .. cat_sc .. "\" is not valid.")) or nil)
		sc = cat_sc
	else
		sc = (sc and (require("Module:scripts").getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")) or nil)
	end
	
	-- Gather basic parameters
	local sort_key = args["sort"]
	local pos = args[2]
	local cat2 = args["cat2"]
	local cat3 = args["cat3"]
	
	-- Gather headwords and transliterations
	local heads = {}
	local translits = {}
	local head = args["head"] or ""
	local translit = args["tr"]
	local i = 1
	
	while head do
		if head then
			table.insert(heads, head)
			translits[#heads] = translit
		end
		
		i = i + 1
		head = args["head" .. i]
		translit = args["tr" .. i]
	end
	
	-- Gather gender and number specifications
	-- Iterate over all gn parameters (g2, g3 and so on) until one is empty
	local genders = {}
	local g = args["g"]
	local i = 2
	
	while g do
		table.insert(genders, g)
		g = args["g" .. i]
		i = i + 1
	end
	
	-- Gather inflected forms
	local inflections = {}
	
	local i = 1
	local label = args[i * 2 + 1]
	local accel = args["f" .. i .. "accel"]
	local request = args["f" .. i .. "request"]
	local parts = {label = label, accel = accel, request = request}
	
	local m_scripts = nil
	
	while label do
		local term = args[i * 2 + 2]
		local alt = args["f" .. i .. "alt"]
		local sc = args["f" .. i .. "sc"]
		local id = args["f" .. i .. "id"]
		local translit = args["f" .. i .. "tr"]
		local gender = args["f" .. i .. "g"]
		local qualifier = args["f" .. i .. "qual"]
		local nolink = args["f" .. i .. "nolink"]
		local lang = args["f" .. i .. "lang"]
		
		if lang ~= nil then
			lang = require("Module:languages").getByCode(lang) or error("The language code \"" .. lang .. "\" is not valid.")
		end
		
		if term or alt then
			if sc then
				m_scripts = m_scripts or require("Module:scripts")
				sc = (sc and (m_scripts.getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")) or nil)
			end
			
			table.insert(parts, {term = term, alt = alt, sc = sc, id = id, translit = translit, genders = {gender}, qualifiers = {qualifier}, nolink = nolink, lang = lang})
		end
		
		i = i + 1
		label = args[i * 2 + 1]
		accel = args["f" .. i .. "accel"]
		request = args["f" .. i .. "request"]
		
		-- If the next label is not "or" then insert the previous one and create a new one.
		if label ~= "or" then
			-- Only insert if the previous label is not empty.
			if (parts.label or "") ~= "" then
				table.insert(inflections, parts)
			end
			
			parts = {label = label, accel = accel, request = request}
		end
	end
	
	-- Get/set categories
	local categories = {}
	local tracking_categories = {}
	
	if pos then
		if not pos:find("s$") and not invariable[pos] then
			--require("Module:debug").track("head tracking/singular category")
			
			-- Make the plural form of the part of speech
			if pos:find("x$") then
				pos = pos .. "es"
			else
				pos = pos .. "s"
			end
		end
		
		table.insert(categories, lang:getCanonicalName() .. " " .. pos .. (cat_sc and " in " .. cat_sc:getCategoryName() or ""))
	end
	
	if cat2 then
		table.insert(categories, lang:getCanonicalName() .. " " .. cat2)
	end
	
	if cat3 then
		table.insert(categories, lang:getCanonicalName() .. " " .. cat3)
	end
	
	return require("Module:headword").full_headword(lang, sc, heads, translits, genders, inflections, categories, sort_key) ..
		require("Module:utilities").format_categories(tracking_categories, lang, sort_key)
end

return export