local export = {}
local U = require("Module:string/char")
local acute = U(0x301) -- combining acute
local grave = U(0x300) -- combining grave
local composed_accents = {
= 'a/', = 'a\\',
= 'i/', = 'i\\',
= 'u/', = 'u\\',
= 'e/', = 'e\\',
= 'o/', = 'o\\',
= '/', = '\\',
}
local normalize_accents = {
= '/', = '\\',
}
local function change_accent(text)
-- normalize accent placement
text = mw.ustring.gsub(text, '()()', function(a, iu) return "a" .. iu .. normalize_accents end)
text = mw.ustring.gsub(text, '.', composed_accents)
return text
end
local function detect_lateral_flap(text)
-- convert jihvamuliya first
text = mw.ustring.gsub(text, "x", "Z")
-- an "ḷ" initially before a non-vowel or between two non-vowels vowel is assumed to be "x"
text = mw.ustring.gsub(text, "^ḷ()", "x%1")
text = mw.ustring.gsub(text, "()ḷ()", "%1x%2")
-- all others are assumed to be "L"
text = mw.ustring.gsub(text, "ḷ", "L")
return text
end
local tt = {
= {
--consonants
= "K", = "G",
= "C", = "J",
= "W", = "Q",
= "T", = "D",
= "P", = "B",
},
= {
-- vowels
= "E",
= "O",
},
= {
-- chandrabindu
= '~'
},
= {
--consonants
= "N",
= "Y",
= "w", = "q", = "R",
= "S", = "z", -- = "L"
--vowels
= "A",
= "I",
= "U",
= "f", = "F",
= "X", -- = "x",
-- avagraha
= "",
--other
= "M",
= "H", -- = "Z"
= "V",
},
}
function export.tr(text, lang, sc)
text = mw.ustring.toNFC(text)
text = change_accent(text)
text = detect_lateral_flap(text)
text = mw.ustring.gsub(text, 'h', tt)
text = mw.ustring.gsub(text, 'a', tt)
text = mw.ustring.gsub(text, 'm̐', tt)
text = mw.ustring.gsub(text, '.', tt)
return text
end
return export