Module:Ancient Greek words with English derivatives
Jump to navigation
Jump to search
- The following documentation is located at Module:Ancient Greek words with English derivatives/documentation. [edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
local export = {}
local function interpret_character_entities(text)
return text:gsub(
"&(#?)(x?)([^;]+);",
function (numeric, hexadecimal, code)
if numeric == "#" then
if hexadecimal == "x" then
return mw.ustring.char(tonumber(code, 16))
else
return mw.ustring.char(tonumber(code))
end
end
end)
end
-- U+0304 COMBINING MACRON, U+0306 COMBINING BREVE
local function remove_macron_breve(text)
return mw.ustring.toNFD(text):gsub("\204[\132\134]", "")
end
-- U+0300 COMBINING GRAVE ACCENT, U+0301 COMBINING ACUTE ACCENT, U+0342 COMBINING GREEK PERISPOMENI
local function remove_accents(text)
return mw.ustring.toNFD(interpret_character_entities(text)):gsub("\204[\129\128]", ""):gsub("\205\130", "")
end
local function link(text)
text = interpret_character_entities(text)
return '<span class="Polyt" lang="grc">[['
.. remove_macron_breve(text)
.. '|' .. text .. ']]</span>'
end
local function tag(text)
return '<span class="Polyt" lang="grc">' .. text .. '</span>'
end
local function form_English_link(entry, alt)
return "[[" .. entry .. "#English|" .. (alt ~= "" and alt or entry) .. "]]"
end
local function English_link(text)
if not text or text == "" then
return "—"
elseif text:find("[[", 1, true) then
return text:gsub("%[%[([^|%]]+)|?(.-)%]%]", form_English_link)
else
return form_English_link(text)
end
end
local auto_subtable_mt = {
__index = function(self, key)
local val = {}
self[key] = val
return val
end,
}
local function auto_subtable()
return setmetatable(
{},
auto_subtable_mt)
end
local function make_row_table(cells, column_count)
local trim = mw.text.trim
local rows = auto_subtable()
local column_number = 0
local row_number = 1
for i, cell in ipairs(cells) do
if column_number == column_count then
column_number = 1
row_number = row_number + 1
else
column_number = column_number + 1
end
rows[row_number][column_number] = trim(cell)
end
-- Remove auto-subtabling.
setmetatable(rows, nil)
return rows
end
local function print_table(rows)
local output = {}
for i, row in ipairs(rows) do
row[1] = interpret_character_entities(row[1])
output[i] = ("|-\n| %s || %s || %s || %s || %s || %s\n")
:format(link(row[1]), (require("Module:languages").getByCode("grc"):transliterate(row[1])), tag(remove_accents(row[2])), row[3] or "", row[4] or "", English_link(row[5]))
end
table.insert(output, 1, '{| class="wikitable"\n! colspan="2" | Citation form || colspan="2" | Root form || Meaning || English derivative\n')
table.insert(output, "|}")
return table.concat(output)
end
function export.Greek_derivative_table(frame)
local args = frame:getParent().args
return print_table(make_row_table(args, 5))
end
return export