Module:headword/templates and Module:headword/templates/sandbox: Difference between pages

(Difference between pages)
Jump to navigation Jump to search
Content deleted Content added
m remove no-longer-need 'etym_lang = true' setting (manually assisted)
 
Created page with "local export = {} -- Part of speech types that should not be pluralized. local invariable = mw.loadData("Module:headword/data").invariable function export.head_t(frame) local plain_param = {} local list_with_holes = {list = true, allow_holes = true} local boolean_list_with_holes = {list = true, allow_holes = true, type = "boolean"} local params = { [1] = {required = true, default = "und"}, ["sc"] = plain_param, ["sort"] = plain_param, [2] = {required = t..."
 
Line 1: Line 1:
local process_params = require("Module:parameters").process

local export = {}
local export = {}


-- Part of speech types that should not be pluralized.
local function get_args(frame)
local = mw.loadData("Module:headword/data")
local boolean = {type = "boolean"}
local boolean_list_allow_holes = {type = "boolean", list = true, allow_holes = true}
local list_allow_holes = {list = true, allow_holes = true}
local plain = {}
return process_params(frame:getParent().args, {
[1] = {required = true, type = "language", default = "und"},
["sc"] = {type = "script"},
["sort"] = plain,


function (frame)
local plain_param = {}
local = {list = true, allow_holes = true}
local = {list = true, allow_holes = true}
local = {
[1] = {required = true, default = "und"},
["sc"] = ,
["sort"] = ,
[2] = {required = true, default = "nouns"},
[2] = {required = true, default = "nouns"},
["sccat"] = boolean,
["sccat"] = boolean,
["noposcat"] = boolean,
["noposcat"] = boolean,
["nomultiwordcat"] = boolean,
["nomultiwordcat"] = boolean,
["nogendercat"] = boolean,
["nogendercat"] = boolean,
["nopalindromecat"] = boolean,
["nopalindromecat"] = boolean,
["nolinkhead"] = boolean,
[""] = boolean,
["autotrinfl"] = boolean,
[""] = ,
["cat2"] = plain,
[""] = ,
["cat3"] = plain,
[""] = ,
["cat4"] = plain,
["head"] = list_allow_holes,
["head"] = ,
["id"] = plain,
["id"] = ,
["tr"] = list_allow_holes,
["tr"] = ,
["ts"] = list_allow_holes,
["ts"] = ,
["gloss"] = plain,
["g"] = {list = true},
["g"] = {list = true},
["g\1qual"] = list_allow_holes,
["g"] = ,
[3] = list_allow_holes,
[3] = ,
["f\1accel-form"] = list_allow_holes,
["f-form"] = ,
["f\1accel-translit"] = list_allow_holes,
["f-translit"] = ,
["f\1accel-lemma"] = list_allow_holes,
["f-lemma"] = ,
["f\1accel-lemma-translit"] = list_allow_holes,
["f-lemma-translit"] = ,
["f\1accel-gender"] = list_allow_holes,
["f-gender"] = ,
["f\1accel-nostore"] = boolean_list_allow_holes,
["f-nostore"] = ,
["f\1request"] = list_allow_holes,
["f"] = ,
["f\1alt"] = list_allow_holes,
["f"] = ,
["f\1lang"] = {list = true, allow_holes = true, type = "language"},
["f"] = ,
["f\1sc"] = {list = true, allow_holes = true, type = "script"},
["f"] = ,
["f\1id"] = list_allow_holes,
["f"] = ,
["f\1tr"] = list_allow_holes,
["f"] = ,
["f\1ts"] = list_allow_holes,
["f"] = ,
["f\1g"] = list_allow_holes,
["f"] = ,
["f\1qual"] = list_allow_holes,
["f"] = ,
["f\1autotr"] = boolean_list_allow_holes,
["f"] = ,
["f\1nolink"] = boolean_list_allow_holes,
["f"] = ,
})
}
end
local = require("Module:parameters").process

function export.head_t(frame)
local function track(page)
require("Module:debug/track")("headword/templates/" .. page)
return true
end

local args = get_args(frame)
-- Get language and script information
-- Get language and script information
local data = {}
local data = {}
data.lang = require("Module:languages").getByCode(args[1]) or require("Module:languages").err(args[1], 1)
data.lang = args[1]
data.sc = args["sc"]
data.sccat = args["sccat"]
data.sort_key = args["sort"]
data.sort_key = args["sort"]
data.heads = args["head"]
data.heads = args["head"]
Line 73: Line 62:
data.translits = args["tr"]
data.translits = args["tr"]
data.transcriptions = args["ts"]
data.transcriptions = args["ts"]
data.gloss = args["gloss"]
data.genders = args["g"]
data.genders = args["g"]
-- This shouldn't really happen.
for i = 1,args["head"].maxindex do
if not args["head"][i] then
track("head-with-holes")
end
end
for k, v in pairs(args["gqual"]) do
for k, v in pairs(args["gqual"]) do
if k ~= "maxindex" then
if k ~= "maxindex" then
Line 91: Line 73:
end
end
end
end

-- Script
data.sc = args["sc"] and require("Module:scripts").getByCode(args["sc"], "sc") or nil
data. = args[]


-- Part-of-speech category
-- Part-of-speech category
data.pos_category = args[2]
data.pos_category = args[2]
data.noposcat = args["noposcat"]
data.noposcat = args["noposcat"]

if not data.pos_category:find("s$") and not invariable[data.pos_category] then
local headword_data = mw.loadData("Module:headword/data")

-- Check for headword aliases and then pluralize if the POS term does not have an invariable plural.
data.pos_category = headword_data.pos_aliases[data.pos_category] or data.pos_category
if not data.pos_category:find("s$") and not headword_data.invariable[data.pos_category] then
-- Make the plural form of the part of speech
-- Make the plural form of the part of speech
data.pos_category = data.pos_category:gsub("x$", "%0e") .. "s"
data.pos_category:("x$",
data.pos_category = data.pos_category
else
data.pos_category = data.pos_category .. "s"
end
end
end

-- Additional categories.
-- Additional categories
data.categories = {}
data.categories = {}
data.whole_page_categories = {}
data.nomultiwordcat = args["nomultiwordcat"]
data.nomultiwordcat = args["nomultiwordcat"]
data.nogendercat = args["nogendercat"]
data.nogendercat = args["nogendercat"]
data.nopalindromecat = args["nopalindromecat"]
data.nopalindromecat = args["nopalindromecat"]

if args["cat2"] then
if args["cat2"] then
table.insert(data.categories, data.lang:getFullName() .. " " .. args["cat2"])
table.insert(data.categories, data.lang:() .. " " .. args["cat2"])
end
end

if args["cat3"] then
if args["cat3"] then
table.insert(data.categories, data.lang:getFullName() .. " " .. args["cat3"])
table.insert(data.categories, data.lang:() .. " " .. args["cat3"])
end
end

if args["cat4"] then
if args["cat4"] then
table.insert(data.categories, data.lang:getFullName() .. " " .. args["cat4"])
table.insert(data.categories, data.lang:() .. " " .. args["cat4"])
end
end

-- Headword linking
data.nolinkhead = args["nolinkhead"]

-- Inflected forms
-- Inflected forms
data.inflections = {enable_auto_translit = args["autotrinfl"]}
data.inflections = {enable_auto_translit = args["autotrinfl"]}

for i = 1, math.ceil(args[3].maxindex / 2) do
for i = 1, math.ceil(args[3].maxindex / 2) do
local infl_part = {
local infl_part = {
Line 151: Line 133:
id = args["fid"][i],
id = args["fid"][i],
lang = args["flang"][i],
lang = args["flang"][i],
nolinkinfl = args["fnolink"][i],
= args["fnolink"][i],
q = {args["fqual"][i]},
= {args["fqual"][i]},
sc = args["fsc"][i],
sc = args["fsc"][i],
translit = args["ftr"][i],
translit = args["ftr"][i],
transcription = args["fts"][i],
transcription = args["fts"][i],
}
}
if form.lang then
form.lang = require("Module:languages").getByCode(form.lang) or require("Module:languages").err(form.lang, "f" .. i .. "lang")
end
if form.sc then
form.sc = require("Module:scripts").getByCode(form.sc) or error("The script code \"" .. form.sc .. "\" is not valid.")
end
-- If no term or alt is given, then the label is shown alone.
-- If no term or alt is given, then the label is shown alone.