This module will transliterate text in the Tirhuta script.
The module should preferably not be called directly from templates or other modules.
To use it from a template, use {{xlit}}
.
Within a module, use Module:languages#Language:transliterate.
For testcases, see Module:mai-Tirh-translit/testcases.
tr(text, lang, sc)
text
written in the script specified by the code sc
, and language specified by the code lang
.nil
.-- Transliteration for Maithili in Tirhuta script
local export = {}
local gsub = mw.ustring.gsub
local match = mw.ustring.match
local conv = {
-- consonants
= "k", = "kh", = "g", = "gh", = "ṅ",
= "c", = "ch", = "j", = "jh", = "ñ",
= "ṭ", = "ṭ", = "ḍ", = "ḍh", = "ṇ",
= "t", = "th", = "d", = "dh", = "n",
= "p", = "ph", = "b", = "bh", = "m",
= "y", = "r", = "l", = "v", = "ḷ",
= "ś", = "ṣ", = "s", = "h",
= "ṛ", = "ṛh",
-- vowel diacritics
= "i", = "u", = "ē", = "e", = "ō", = "o", = "ā", = "ī", = "ū",
= "r̥", = "r̥̄", = "ai", = "au", = "l̥", = "l̥̄",
-- vowels
= "a", = "ā", = "i", = "ī", = "u", = "ū",
= "r̥", = "r̥̄", = "l̥", = "l̥̄",
= "ē", = "ai", = "ō", = "au",
= "’", = "ê", = "ô",
= "²", -- avagraha
= "̃", -- chandrabindu
= "̃", -- anusvara
= "̃", -- gvang
= "ḥ", -- visarga
= "", -- virama
= "om̐", -- om
-- numerals
= "0", = "1", = "2", = "3", = "4", = "5", = "6", = "7", = "8", = "9",
-- punctuation
= ".", -- danda
= ".", -- double danda
= "", -- compound separator
-- abbreviation sign
= "."
}
local nasal_assim = {
= "𑒓", = "𑒓", = "𑒓", = "𑒓",
= "𑒘", = "𑒘", = "𑒘", = "𑒘", = "𑒘",
= "𑒝", = "𑒝", = "𑒝", = "𑒝",
= "𑒢", = "𑒢", = "𑒢", = "𑒢", = "𑒢",
= "𑒧", = "𑒧", = "𑒧", = "𑒧", = "𑒧"
}
local perm_cl = {
= true
}
local all_cons, special_cons = "𑒏𑒐𑒑𑒒𑒓𑒔𑒕𑒖𑒗𑒘𑒙𑒚𑒛𑒜𑒝𑒞𑒟𑒠𑒡𑒢𑒣𑒤𑒥𑒦𑒧𑒨𑒩𑒪𑒫𑒮𑒬𑒭𑒯𑒩", "𑒕𑒏𑒐𑒑𑒞𑒮𑒯𑒨𑒟𑒛𑒜𑒚𑒣𑒠𑒝𑒡𑒩𑒭𑒙𑒪𑒫𑒥𑒦𑒛𑒔𑒢𑒬𑒧"
local vowel, vowel_sign = "a𑒱𑒳𑒵𑒹𑒼𑒰𑒲𑒴𑒻𑒾𑒰𑒻𑒽𑒰𑒰𑒽𑒺", "𑒁𑒃𑒅𑒋𑒍𑒂𑒄𑒆𑒇𑒈𑒁𑒺𑒁𑒽𑒫𑓃𑒨𑓃𑒁𑒂𑒌𑒎𑒂𑒋"
local syncope_pattern = '()(𑓃?)a(𑓃?)(?)'
local function rev_string(text)
local result, length = {}, mw.ustring.len(text)
for i = length, 1, -1 do
table.insert(result, mw.ustring.sub(text, i, i))
end
return table.concat(result)
end
function export.tr(text, lang, sc)
text =
gsub(
text,
"(𑓃?)(?)",
function(c, d)
return c .. (d == "" and "a" or d)
end
)
for word in mw.ustring.gmatch(text, "+") do
local orig_word = word
word = rev_string(word)
word = gsub(
word,
'^a(𑓃?)()(.)(.?)',
function(opt, first, second, third)
local a = ""
if match(first, '')
and match(second, '𑓂')
and not perm_cl
or match(first .. second, '𑒨') then
a = "a"
end
return a .. opt .. first .. second .. third
end
)
while match(word, syncope_pattern) do
word = gsub(word, syncope_pattern, "%1%2ᵊ%3%4")
end
word =
gsub(
word,
"(.?)𑓀(.)",
function(succ, prev)
return succ ..
(succ .. prev == "a" and "𑓂𑒧" or
(succ == "" and match(prev, "") and "̃" or nasal_assim or "̃")) ..
prev
end
)
local escaped_orig_word = gsub(orig_word, "%+", "")
text = gsub(text, orig_word, rev_string(word))
text = gsub(text, "𑒖𑓂𑒘", "gy")
end
text = gsub(text, "ā()̃", "ā͠%1")
text = gsub(text, "uu", "u")
text = gsub(text, "aâ", "â")
text = gsub(text, "ii", "i")
text = gsub(text, "()a", "%1")
text = gsub(text, "", "")
text = gsub(text, ".𑓃?", conv)
return mw.ustring.toNFC(text)
end
return export