Module:Dict: Difference between revisions

From Annwan’s Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
 
(12 intermediate revisions by the same user not shown)
Line 1: Line 1:
local exports = {}
local exports = {}
 
local def = require("Module:Utils").def
local langdata = require('Module:Data/Langs')
local langdata = require('Module:Data/Langs')
local posdata = require('Module:Data/POS')
local posdata = require('Module:Data/POS')
local scriptdata = require("Module:Data/Scripts")


exports.head = function(frame)
exports.head = function(frame)
Line 9: Line 10:
local pos = frame.args["pos"]
local pos = frame.args["pos"]
local translit = frame.args["translit"]
local translit = frame.args["translit"]
local ss = frame.args["ss"]
local sc = frame.args["sc"]
local sc = frame.args["sc"]
local ipa = frame.args["ipa"]
local ipa = frame.args["ipa"]
assert(lang)
assert(pos)
assert(ipa)
ipa = frame:expandTemplate{ title = "IPA", args = {"/" .. ipa .. "/" }}
ipa = frame:expandTemplate{ title = "IPA", args = {"/" .. ipa .. "/" }}
if (not translit) or translit == "" then
if def(translit, "") == "" then
translit = ""
translit = ""
else
else
translit = " (" .. translit .. ")"
translit = " (" .. translit .. ")"
end
end
local head
if sc and sc ~= "" then
if sc and sc ~= "" then
headword = frame:expandTemplate{ title = 'Scr', args = { sc, headword}}
head = ss ~= "" and ss or headword
head = frame:expandTemplate{ title = 'Scr', args = { sc, head, float = scriptdata._getDictfloat(sc), addclass="dict" }}
translit = scriptdata._getDictfloat(sc) == "" and " (" .. headword .. ")" or headword
else
else
headword = "'''" .. headword .. "'''"
head = "'''" .. headword .. "'''"
end
return head .. translit .. " " .. ipa .. " ''" .. pos .. ".''\n"
.. "[[Category:" .. langdata._getDisplayName(lang) .. " " .. tostring(posdata._get(pos)) .. "]]\n"
.. "[[Category:" .. tostring(langdata._getDisplayName(lang)) .. " Lemmas]]"
end
 
exports.ex = function(frame)
local lang = def(frame.args.lang, "")
local sc = def(frame.args.sc, langdata._getScript(lang))
local s = frame.args.s
local ss = def(frame.args.ss, s)
local t = frame.args.t
local dictfloat = scriptdata._getDictfloat(sc)
local body = "<div>"
if dictfloat ~= "" then
body = frame:expandTemplate{title = 'Scr', args = { sc, ss, float = dictfloat, addclass="dict" }}
.. [[<table>]]
elseif sc ~= "" then
body = [[<table><tr><td>]] .. frame:expandTemplate{title = 'Scr', args = { sc, ss, float = "", addclass="dict" }} .. [[</td></tr>]]
else
body = [[<table>]]
end
body = body .. [[<tr><td>]] .. s .. [[</tr></td>]]
.. [[<tr><td>]] .. t .. [[</tr></td>]]
.. [[</table>]]
body = frame:extensionTag("spoiler", body, {show="Example ▼", hide="Example ▲"})
if lang ~= "" then
body = body .. "[[Category:" .. langdata._getDisplayName(lang) .. " Lemmas with Examples]]"
end
end
return headword .. translit .. " " .. ipa .. " ''" .. pos .. ".''\n"
return body .. "</div>"
.. "[[Category:" .. tostring(langdata[lang].display_name) .. " " .. tostring(posdata[pos]) .. "]]\n"
.. "[[Category:" .. tostring(langdata[lang].display_name) .. " Lemmas]]"
end
end


return exports
return exports

Latest revision as of 17:00, 16 April 2025


local exports = {}
local def = require("Module:Utils").def
local langdata = require('Module:Data/Langs')
local posdata = require('Module:Data/POS')
local scriptdata = require("Module:Data/Scripts")

exports.head = function(frame)
	local headword = frame.args[1]
	local lang = frame.args["lang"]
	local pos = frame.args["pos"]
	local translit = frame.args["translit"]
	local ss = frame.args["ss"]
	local sc = frame.args["sc"]
	local ipa = frame.args["ipa"]
	ipa = frame:expandTemplate{ title = "IPA", args = {"/" .. ipa .. "/" }}
	if def(translit, "") == "" then
		translit = ""
	else
		translit = " (" .. translit .. ")"
	end
	local head
	if sc and sc ~= "" then
		head = ss ~= "" and ss or headword
		head = frame:expandTemplate{ title = 'Scr', args = { sc, head, float = scriptdata._getDictfloat(sc), addclass="dict" }}
		translit = scriptdata._getDictfloat(sc) == "" and " (" .. headword .. ")" or headword
	else
		head = "'''" .. headword .. "'''"
	end
	return head .. translit .. " " .. ipa .. " ''" .. pos .. ".''\n"
		.. "[[Category:" .. langdata._getDisplayName(lang) .. " " .. tostring(posdata._get(pos)) .. "]]\n"
		.. "[[Category:" .. tostring(langdata._getDisplayName(lang)) .. " Lemmas]]"
end

exports.ex = function(frame)
	local lang = def(frame.args.lang, "")
	local sc = def(frame.args.sc, langdata._getScript(lang))
	local s = frame.args.s
	local ss = def(frame.args.ss, s)
	local t = frame.args.t
	local dictfloat = scriptdata._getDictfloat(sc)
	local body = "<div>"
	if dictfloat ~= "" then
		body = frame:expandTemplate{title = 'Scr', args = { sc, ss, float = dictfloat, addclass="dict" }}
					.. [[<table>]]
	elseif sc ~= "" then
		body = [[<table><tr><td>]] .. frame:expandTemplate{title = 'Scr', args = { sc, ss, float = "", addclass="dict" }} .. [[</td></tr>]]
	else
		body = [[<table>]]
	end
	body = body .. [[<tr><td>]] .. s .. [[</tr></td>]]
				.. [[<tr><td>]] .. t .. [[</tr></td>]]
				.. [[</table>]]
	body = frame:extensionTag("spoiler", body, {show="Example ▼", hide="Example ▲"})
	if lang ~= "" then
		body = body .. "[[Category:" .. langdata._getDisplayName(lang) .. " Lemmas with Examples]]"
	end
	return body .. "</div>"
end

return exports