12,564
edits
TheNightAvl (talk | contribs) (Created page with "local export = {} local getArgs = require('Module:Arguments').getArgs local m_inline = require("Module:inline") local m_languages = require("Module:languages") local table_style = "padding: 1em 0 1em 0" -- top right bottom left local cell_style = "padding: 0 1em 0.2em 0" function build_grid(data) local grid = "" local function build(new) grid = grid .. new end local term_count = #data.terms if term_count > 10 then mw.addWarning("<div class=\"noprint maint...") |
TheNightAvl (talk | contribs) No edit summary |
||
| Line 7: | Line 7: | ||
local table_style = "padding: 1em 0 1em 0" -- top right bottom left | local table_style = "padding: 1em 0 1em 0" -- top right bottom left | ||
local cell_style = "padding: 0 1em 0.2em 0" | local cell_style = "padding: 0 1em 0.2em 0" | ||
local punctuation_regex = '[%.%,%(%)%—%!%?%"%:%;%*%/%&%_“”‘’%s]' -- specified because the %p pattern would include the apostrophe, which is still needed in links | |||
function build_grid(data) | function build_grid(data) | ||
| Line 88: | Line 89: | ||
end | end | ||
function export. | function export.show(frame) | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
local lang = m_languages.find_by_code(args[1]).code | local lang = m_languages.find_by_code(args[1]).code | ||
local terms, glosses, translations, IPAs = {}, {}, {}, {} | local terms, glosses, translations, IPAs = {}, {}, {}, {} | ||
local nolinks = args["nolinks"] or args["nolink"] or false | |||
for i, arg in ipairs(args) do | for i, arg in ipairs(args) do | ||
| Line 98: | Line 100: | ||
if mw.ustring.match(arg, "^[^<]+:[^<]+") then arg = mw.ustring.gsub(arg, "^([^<]+):([^<]+)", "%2<alt:%1>") end | if mw.ustring.match(arg, "^[^<]+:[^<]+") then arg = mw.ustring.gsub(arg, "^([^<]+):([^<]+)", "%2<alt:%1>") end | ||
local term, term_args = m_inline.parse(arg) | local term, term_args = m_inline.parse(arg) | ||
if term_args["t"] then | if term_args["t"] then | ||
| Line 113: | Line 114: | ||
end | end | ||
terms[i-1] = frame:expandTemplate{title = "l", args = term_args} | if nolinks or term_args["nolink"] then | ||
terms[i-1] = term | |||
else | |||
-- allow manual bolding | |||
if mw.ustring.match(term, "'''") and term_args["alt"] == nil then | |||
term_args["alt"] = term | |||
term = mw.ustring.gsub(term, "'''", "") | |||
end | |||
--- unlink punctuation at start or end of term | |||
local pre, post | |||
if term_args["alt"] then | |||
pre = mw.ustring.match(term_args["alt"], "^(" .. punctuation_regex .. "+)") or "" | |||
post = mw.ustring.match(term_args["alt"], "(" .. punctuation_regex .. "+)$") or "" | |||
term_args["alt"] = mw.ustring.gsub(term_args["alt"], "^(" .. punctuation_regex .. "+)", "") | |||
term_args["alt"] = mw.ustring.gsub(term_args["alt"], "(" .. punctuation_regex .. "+)$","") | |||
else | |||
pre = mw.ustring.match(term, "^(" .. punctuation_regex .. "+)") or "" | |||
post = mw.ustring.match(term, "(" .. punctuation_regex .. "+)$") or "" | |||
term = mw.ustring.gsub(term, "^(" .. punctuation_regex .. "+)", "") | |||
term = mw.ustring.gsub(term, "(" .. punctuation_regex .. "+)$","") | |||
end | |||
if #term == 0 then | |||
terms[i-1] = pre .. post | |||
else | |||
term_args[1], term_args[2] = lang, term | |||
terms[i-1] = pre .. frame:expandTemplate{title = "l", args = term_args} .. post | |||
end | |||
end | |||
end | end | ||
end | end | ||
| Line 132: | Line 162: | ||
--[[ | --[[ | ||
Debug console test string: | Debug console test string: | ||
=p. | =p.show(mw.getCurrentFrame():newChild{title="whatever",args={"rad", "Gaks,<ipa:[ˈɡaks><g:sheep-NOM.SG>", "vân<pr:vɤn><g:3S.ANIM-DAT>", "gjeș<ipa:jɛʃ><t:relativising particle>", "hreņuog<ipa:ˈxrɛŋuoɡ><g:wool-GEN.SG>", "húe<alt:húe,><ipa:ˈhuːɛ]><g:NEG.PST-DISJ.SG>", ["t"] = "A sheep which had no wool"}}) | ||
]] | ]] | ||