Module:gloss: Difference between revisions
Jump to navigation
Jump to search
TheNightAvl (talk | contribs) No edit summary |
TheNightAvl (talk | contribs) No edit summary |
||
Line 20: | Line 20: | ||
local l_gloss = m_data.aliases[gloss_code] | local l_gloss = m_data.aliases[gloss_code] | ||
if l_gloss then -- check valid gloss (does not necessarily check for standardised glossing practices, just whatever is in form of/data) | if l_gloss then -- check valid gloss (does not necessarily check for standardised glossing practices, just whatever is in form of/data) | ||
local l_link | |||
local l = m_data.labels[l_gloss] | local l = m_data.labels[l_gloss] | ||
if l then l_gloss = l.label end -- check if label has glossary text and update | if l then | ||
l_gloss = l.label | |||
l_link = type(l.glossary) == "string" and l.glossary or l.label | |||
end -- check if label has glossary text and update | |||
glosslet_format = frame:expandTemplate{title = "hover", args = {glosslet_format, l_gloss, noline = args.noline or (args.style == nil and l and args.nolinks == nil), style = args.style}} --[[ format hover text (I spent ages agonising over the logic in excel for the conditions of this system, so here it is) | glosslet_format = frame:expandTemplate{title = "hover", args = {glosslet_format, l_gloss, noline = args.noline or (args.style == nil and l and args.nolinks == nil), style = args.style}} --[[ format hover text (I spent ages agonising over the logic in excel for the conditions of this system, so here it is) | ||
LINKS ENABLED? IN GLOSSARY? (L) NOLINK=1 STYLE NOLINE=1 LINE DISPLAYED? FINAL BOOLEAN FOR NO LINE | LINKS ENABLED? IN GLOSSARY? (L) NOLINK=1 STYLE NOLINE=1 LINE DISPLAYED? FINAL BOOLEAN FOR NO LINE | ||
Line 37: | Line 41: | ||
× × ✓ × ✓ × TRUE | × × ✓ × ✓ × TRUE | ||
-]] | -]] | ||
if l and args.nolinks == nil then glosslet_format = "[[Appendix:Glossary#" .. l_gloss .. "|" .. glosslet_format .. "]]" end | if l and args.nolinks == nil then glosslet_format = "[[Appendix:Glossary#" .. (l_link or l_gloss) .. "|" .. glosslet_format .. "]]" end | ||
-- format links (hover and links MUST be done in this order for the gloss' hover texts to override the links') | -- format links (hover and links MUST be done in this order for the gloss' hover texts to override the links') | ||
end | end |
Latest revision as of 22:03, 17 April 2025
Underlies {{gloss}}
, as well as Module:gloss grid. Uses Module:form of/data.
local export = {}
local getArgs = require('Module:Arguments').getArgs
local m_data = mw.loadData("Module:form of/data")
local delimiters = "%s%p"
function export.show(frame)
local args = getArgs(frame)
local gloss = args[1]
local gloss_keys = {}
for glosslet in gloss:gmatch("[^" .. delimiters .. "]+") do -- split the string into chunks by delimiters
if glosslet:match("^[%d%u]+$") then --[[ match chunks which are valid glosses (i.e. only contain capital letters and numbers)
This method means that you can use capital letters in semantic glosses, such as when you need to gloss proper nouns,
without the capitalisation being mistaken for grammatical glossing. Be wary of glossing acronyms, as “USA”, for example,
will still be parsed as a grammatical gloss on its own.
]]--
local gloss_code = glosslet:lower() -- decapitalise grammatical glosses for correct display under small caps
local glosslet_format = gloss_code:gsub("(%d+)", "<small>%1</small>") -- make numbers small too, as they are unaffected by small caps
local l_gloss = m_data.aliases[gloss_code]
if l_gloss then -- check valid gloss (does not necessarily check for standardised glossing practices, just whatever is in form of/data)
local l_link
local l = m_data.labels[l_gloss]
if l then
l_gloss = l.label
l_link = type(l.glossary) == "string" and l.glossary or l.label
end -- check if label has glossary text and update
glosslet_format = frame:expandTemplate{title = "hover", args = {glosslet_format, l_gloss, noline = args.noline or (args.style == nil and l and args.nolinks == nil), style = args.style}} --[[ format hover text (I spent ages agonising over the logic in excel for the conditions of this system, so here it is)
LINKS ENABLED? IN GLOSSARY? (L) NOLINK=1 STYLE NOLINE=1 LINE DISPLAYED? FINAL BOOLEAN FOR NO LINE
✓ ✓ × × × × TRUE
✓ × × × × ✓ FALSE
× ✓ ✓ × × ✓ FALSE
× × ✓ × × ✓ FALSE
✓ ✓ × ✓ × ✓ FALSE
✓ × × ✓ × ✓ FALSE
× ✓ ✓ ✓ × ✓ FALSE
× × ✓ ✓ × ✓ FALSE
✓ ✓ × × ✓ × TRUE
✓ × × × ✓ × TRUE
× ✓ ✓ × ✓ × TRUE
× × ✓ × ✓ × TRUE
-]]
if l and args.nolinks == nil then glosslet_format = "[[Appendix:Glossary#" .. (l_link or l_gloss) .. "|" .. glosslet_format .. "]]" end
-- format links (hover and links MUST be done in this order for the gloss' hover texts to override the links')
end
gloss_keys[glosslet] = '<span style="font-variant: small-caps">' .. glosslet_format .. '</span>'
end
end
for search, replace in pairs(gloss_keys) do gloss = gloss:gsub(search, replace) end
return gloss
end
return export
--[[
=p.show(mw.getCurrentFrame():newChild{title="whatever",args={"sheep-NOM.SG 3S.ANIM-DAT;SG wool-GEN.SG NEG.PST-DISJ=SG Radestria.DAT | "}})
]]--