Module:Dni-utils
From Guild of Archivists
Documentation for this module may be created at Module:Dni-utils/doc
--
-- This implements several useful functions for dealing with D'ni text in the Wiki.
--
-- parsed_dni() returns a string in which every component is linked to its appropriate Dictionary namespace entry.
-- dnifont2ots() converts a Dnifont string to an ots one
-- dnifont2nts() converts a Dnifont string to an nts one
local p = {}
local args = {}
local origArgs
local root
local output = ''
local function num2dnum(str,sep)
str = str or ''
str = mw.text.trim(str)
if (sep == nil or sep == '') then
sep = "|"
end
local result = "nil"
local num = tonumber(str)
if (num ~= nil and num >= 0) then
result = num % 25
while (num >= 25) do
num = math.floor(num / 25)
result = tostring(num % 25)..sep..result
end
end
return result
end
local function dnum2num(str,sep)
str = str or ''
sep = sep or ''
local result = mw.text.trim(str)
result = mw.ustring.gsub(result,"%d%d", {["24"] = "O",
["23"] = "N",
["22"] = "M",
["21"] = "L",
["20"] = "K",
["19"] = "J",
["18"] = "I",
["17"] = "H",
["16"] = "G",
["15"] = "F",
["14"] = "E",
["13"] = "D",
["12"] = "C",
["11"] = "B",
["10"] = "A"
})
result = mw.ustring.gsub(result,sep,"")
result = tonumber(result,25)
return result
end
local function dnifont2ots(str)
local output = mw.text.trim(str)
output = mw.ustring.gsub(str,"%S", {["S"] = "sh",
["T"] = "th",
["O"] = "oy",
["c"] = "ch",
["a"] = "ah",
["E"] = "ee",
["A"] = "ay",
["u"] = "uh",
["U"] = "oo",
["x"] = "ts",
["d"] = "dh",
["D"] = "d",
["k"] = "kh",
["K"] = "k",
["I"] = "ai",
["å"] = "a",
})
return output
end
local function dnifont2nts(str)
local output = mw.text.trim(str)
output = mw.ustring.gsub(str,"%S", {["S"] = "š",
["T"] = "þ",
["O"] = "ó",
["c"] = "ç",
["E"] = "í",
["A"] = "é",
["U"] = "ú",
["x"] = "c",
["d"] = "ð",
["D"] = "d",
["k"] = "x",
["K"] = "k",
["I"] = "á",
["å"] = "æ",
})
return output
end
-- To be called from other Modules
-- For call by other Modules
function p._num2dnum(str,sep)
return num2dnum(str,sep)
end
function p._dnum2num(str,sep)
return dnum2num(str,sep)
end
function p._dnum2dnifont(str,min,use25,useWrap)
return dnum2dnifont(str,min,use25,useWrap)
end
function p._dnifont2dnum(str,sep)
return dnifont2dnum(str,sep)
end
function p._num2dnifont(str,min,use25,useWrap)
return dnum2dnifont(num2dnum(str),min,use25,useWrap)
end
function p._dnifont2ots(str)
return dnifont2ots(str)
end
function p._dnifont2nts(str)
return dnifont2nts(str)
end
-- To be called from templates
function p.dnifont2ots(frame)
return dnifont2ots(frame.args[1])
end
function p.dnifont2nts(frame)
return dnifont2nts(frame.args[1])
end
return p