Module:example: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
TheNightAvl (talk | contribs) No edit summary |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 8: | Line 8: | ||
[3] = {}, | [3] = {}, | ||
["inline"] = {type = "boolean"}, | ["inline"] = {type = "boolean"}, | ||
["nocat"] = {type = "boolean"}, | |||
} | |||
local params_inline = { | |||
[1] = {required = true}, | |||
[2] = {required = true}, | |||
[3] = {}, | |||
["inline"] = {type = "boolean", default = true}, | |||
["nocat"] = {type = "boolean"}, | ["nocat"] = {type = "boolean"}, | ||
} | } | ||
function export.make_example(language, sentence, gloss, inline, nocat) | |||
local translation = gloss and (inline and (" ― " .. gloss) or ("<dl><dd>" .. gloss .. "</dd></dl>")) or "" | |||
local cats = nocat and "" or ("[[Category:" .. language.name .. " terms with usage examples]]") | |||
return '<div class="h-example">' .. m_formatting.wrap_face(mw.ustring.gsub(sentence,"%*([^%*]+)*","'''%1'''"), language, "example") .. mw.ustring.gsub(translation,"%*([^%*]+)*","'''%1'''") .. '</div>' .. cats | |||
end | |||
function export.show(frame) | function export.show(frame) | ||
local args = require("Module:parameters").process(frame:getParent().args, params) | local args = require("Module:parameters").process(frame:getParent().args, params) | ||
local language = m_languages.get_by_code(args[1]) | local language = m_languages.get_by_code(args[1]) | ||
return export.make_example(language, args[2], args[3], args["inline"], args["nocat"]) | |||
local | end | ||
return | |||
function export.show_inline(frame) | |||
local args = require("Module:parameters").process(frame:getParent().args, params_inline) | |||
local language = m_languages.get_by_code(args[1]) | |||
return export.make_example(language, args[2], args[3], args["inline"], args["nocat"]) | |||
end | end | ||
return export | return export |
Latest revision as of 17:28, 24 March 2024
Implements {{example}}
.
local export = {}
local m_formatting = require("Module:formatting")
local m_languages = require("Module:languages")
local params = {
[1] = {required = true},
[2] = {required = true},
[3] = {},
["inline"] = {type = "boolean"},
["nocat"] = {type = "boolean"},
}
local params_inline = {
[1] = {required = true},
[2] = {required = true},
[3] = {},
["inline"] = {type = "boolean", default = true},
["nocat"] = {type = "boolean"},
}
function export.make_example(language, sentence, gloss, inline, nocat)
local translation = gloss and (inline and (" ― " .. gloss) or ("<dl><dd>" .. gloss .. "</dd></dl>")) or ""
local cats = nocat and "" or ("[[Category:" .. language.name .. " terms with usage examples]]")
return '<div class="h-example">' .. m_formatting.wrap_face(mw.ustring.gsub(sentence,"%*([^%*]+)*","'''%1'''"), language, "example") .. mw.ustring.gsub(translation,"%*([^%*]+)*","'''%1'''") .. '</div>' .. cats
end
function export.show(frame)
local args = require("Module:parameters").process(frame:getParent().args, params)
local language = m_languages.get_by_code(args[1])
return export.make_example(language, args[2], args[3], args["inline"], args["nocat"])
end
function export.show_inline(frame)
local args = require("Module:parameters").process(frame:getParent().args, params_inline)
local language = m_languages.get_by_code(args[1])
return export.make_example(language, args[2], args[3], args["inline"], args["nocat"])
end
return export