Module:Fontize

From Tsal Wiki
Jump to navigation Jump to search

Documentation for this module may be created at Module:Fontize/doc

local p = {}

local romanizationTable = {
--  {font encoding, unicode romanization}
    {"c","c"},
    {"D","ż"},
    {"L","ł"},
    {"X","ğ"},
    {"K","q"},
    {"S","š"},
    {"Z","ž"},
    {"C","č"},
    {"R","ř"},
    {"ah","ā"},
    {"eh","ē"},
    {"ih","ī"},
    {"oh","ō"},
    {"uh","ū"},
-- capitalized forms
    {"c","C"},
    {"D","Ż"},
    {"L","Ł"},
    {"X","Ğ"},
    {"K","Q"},
    {"S","Š"},
    {"Z","Ž"},
    {"C","Č"},
    {"R","Ř"},
    {"ah","Ā"},
    {"eh","Ē"},
    {"ih","Ī"},
    {"oh","Ō"},
    {"uh","Ū"},
}

local function rewriteWord(t, from, to)
    local s = t
    for _, rule in ipairs(romanizationTable) do
        s = mw.ustring.gsub(s,rule[from], rule[to])
    end
    return s
end

local function fontizeWord(t)
	return rewriteWord(t, 2, 1)
end

function p.fontize(frame)
	local words = frame.args[1]
	out, _ = mw.ustring.gsub(words,"(%w+)", fontizeWord)
	return out
end	

return p