Module:languages-oow: Difference between revisions
Jump to navigation
Jump to search
TheNightAvl (talk | contribs) No edit summary |
TheNightAvl (talk | contribs) No edit summary |
||
Line 10: | Line 10: | ||
function format_gender(gender) | function format_gender(gender) | ||
local temp = gender | local temp = gender | ||
for code in string.gmatch(gender, " | for code in string.gmatch(gender, "[a-z]+") do | ||
gender_obj = assert(available_genders[code], "Invalid gender code detected") | gender_obj = assert(available_genders[code], "Invalid gender code detected") | ||
temp = string.gsub(temp, code, '<abbr title="' .. gender_obj.hint .. '">' .. gender_obj.label .. "</abbr>") | temp = string.gsub(temp, code, '<abbr title="' .. gender_obj.hint .. '">' .. gender_obj.label .. "</abbr>") |
Revision as of 22:14, 25 December 2024
Underlies {{def+}}
.
local export = {}
local getArgs = require('Module:Arguments').getArgs
local m_inline = require("Module:inline")
local data = mw.loadData("Module:languages-oow/data")
local available_genders = mw.loadData("Module:gender and number/data")
function format_gender(gender)
local temp = gender
for code in string.gmatch(gender, "[a-z]+") do
gender_obj = assert(available_genders[code], "Invalid gender code detected")
temp = string.gsub(temp, code, '<abbr title="' .. gender_obj.hint .. '">' .. gender_obj.label .. "</abbr>")
end
return '<span class="gender">' .. temp .. "</span>"
end
function export.get_flag(code)
local language = data[code]
return language.flag or ("[" .. string.upper(language.code) .. "]")
end
function export.get_linked_name(code)
return "[[w:" .. data[code].wiki .. "|" .. data[code].name .. "]]"
end
function export.get_linked_term(code, term, gender)
local out = "[[wikt:" .. term .. "#" .. data[code].name .. "|" .. term .. "]]"
if gender then out = out .. " " .. format_gender(gender) end
return out
end
function export.definition(frame)
local args = getArgs(frame)
if args[2] == nil then error("At least one term is required") end
local language = assert(data[args[1]], "First argument needs to be a recognised language code")
local out = export.get_flag(language.code) .. " "
local i = 2
while args[i] or args[i+1] do
if args[i] == "" or args[i] == nil then
out = out .. "; "
else
term, term_args = m_inline.parse(args[i])
if not (i == 2 or args[i-1] == "" or args[i-1] == nil) then out = out .. ", " end
out = out .. export.get_linked_term(language.code, term, term_args.g)
end
i = i + 1
end
if not args["nocat"] then out = out .. "[[Category:Terms with " .. language.name .. " translations]]" end
return out
end
return export
--[[
Debug console test string:
=p.definition(mw.getCurrentFrame():newChild{title="whatever",args={"de", "Zustand", "Verfassung"}})
]]--