Module:krv-script
Jump to navigation
Jump to search
Documentation for this module may be created at Module:krv-script/documentation
local export = {}
local getArgs = require("Module:Arguments").getArgs
local m_languages = require("Module:languages")
local m_links = require("Module:links")
local correspondences = {
{"tth","თთ"},
{"pph","ფფ"},
{"kkh","ქქ"},
{"ddẓ","ჯჯ"},
{"ddz","ძძ"},
{"c̣c̣h","ჩჩ"},
{"cch","ცც"},
{"th","თ"},
{"ph","ფ"},
{"kh","ქ"},
{"dẓ","ჯ"},
{"dz","ძ"},
{"c̣h","ჩ"},
{"ch","ც"},
{"ẓ","ჟ"},
{"ṣ","შ"},
{"ṛ","ღ"},
{"ṇ","ჹ"},
{"ḥ","ხ"},
{"z","ზ"},
{"v","ვ"},
{"u","უ"},
{"t","ტ"},
{"s","ს"},
{"r","რ"},
{"p","პ"},
{"o","ო"},
{"n","ნ"},
{"m","მ"},
{"l","ლ"},
{"k","კ"},
{"i","ი"},
{"h","ჰ"},
{"g","გ"},
{"f","ჶ"},
{"e","ე"},
{"d","დ"},
{"c̣","ჭ"},
{"c","წ"},
{"b","ბ"},
{"a","ა"},
}
local correspondences_old = {
{"ččh","ⴙⴙ"},
{"tth","ⴇⴇ"},
{"pph","ⴔⴔ"},
{"kkh","ⴕⴕ"},
{"ddž","ⴟⴟ"},
{"ddz","ⴛⴛ"},
{"cch","ⴚⴚ"},
{"čh","ⴙ"},
{"th","ⴇ"},
{"ph","ⴔ"},
{"kh","ⴕ"},
{"dž","ⴟ"},
{"dz","ⴛ"},
{"ch","ⴚ"},
{"θ","ⴇ"},
{"β","ⴁ"},
{"ɸ","ⴔ"},
{"ɣ","ⴖ"},
{"ž","ⴏ"},
{"š","ⴘ"},
{"ŋ","ⴂ"},
{"č","ჩ"},
{"ð","ⴃ"},
{"z","ⴆ"},
{"x","ⴞ"},
{"w","ⴣ"},
{"u","ⴓ"},
{"t","ⴒ"},
{"s","ⴑ"},
{"r","ⴐ"},
{"p","ⴎ"},
{"o","ⴍ"},
{"n","ⴌ"},
{"m","ⴋ"},
{"l","ⴊ"},
{"k","ⴉ"},
{"j","ⴢ"},
{"i","ⴈ"},
{"h","ⴠ"},
{"g","ⴂ"},
{"e","ⴄ"},
{"d","ⴃ"},
{"c","ⴜ"},
{"b","ⴁ"},
{"a","ⴀ"},
}
function demacron(text)
text = mw.ustring.gsub(text, "ā", "a")
text = mw.ustring.gsub(text, "ē", "e")
text = mw.ustring.gsub(text, "ī", "i")
text = mw.ustring.gsub(text, "ō", "o")
text = mw.ustring.gsub(text, "ū", "u")
text = mw.ustring.gsub(text, "̄", "u")
return text
end
function convert(text, old, classical)
local it = correspondences
if old then it = correspondences_old end
text = mw.ustring.lower(text)
text = demacron(text)
for _, c in ipairs(it) do
text = mw.ustring.gsub(text, c[1], c[2])
end
if classical then
text = mw.ustring.gsub(text, "%p", "")
text = mw.ustring.gsub(text, "%s", "·")
text = '<span style="font-family: serif">' .. text .. '</span>'
end
return text
end
function export.show(frame)
local args = getArgs(frame)
local parameters = {}
local text = ""
for i, arg in ipairs(args) do
if i == 1 then
text = arg
else
parameters[arg] = true
end
end
if parameters["link"] then return demacron(text) end
local script = convert(text, parameters["old"] or false, parameters["classical"] or false)
local out = script
if parameters["both"] then
local delim = args["delim"] or " • "
local pre = args["pre"] or ""
local post = args["post"] or ""
if parameters["demacron"] then text = demacron(text) end
out = pre .. out .. delim .. text .. post
end
if parameters["inline"] then
return demacron(text) .. "<alt:" .. out .. ">"
elseif parameters["linked"] then
local lang = "krv"
if args["old"] then lang = "krv-o" end
return m_links.full_link{term = demacron(text), alt = out, language = m_languages.get_by_code(lang)}
else
return out
end
end
return export
--[[
Debug console test string:
=p.show(mw.getCurrentFrame():newChild{title="whatever",args={"nēphas"}})
]]--