This module will transliterate Maithili language text per WT:MAI TR.
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-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
local export = {}
local gsub = mw.ustring.gsub
local match = mw.ustring.match
local conv = {
-- consonants
= "k", = "kh", = "g", = "gh", = "ṅ",
= "c", = "ch", = "j", = "jh", = "ñ",
= "ṭ", = "ṭh", = "ḍ", = "ḍh", = "ṇ",
= "t", = "th", = "d", = "dh", = "n",
= "p", = "ph", = "b", = "bh", = "m",
= "y", = "r", = "l", = "v", = "ḷ",
= "ś", = "ṣ", = "s", = "h",
= "q", = "x", = "ġ", = "ḻ",
= "z", = "ž", = "ṛ", = "ṛh",
= "f", = "ṉ", = "ṟ",
-- vowel diacritics
= "i", = "u", = "ē", = "e", = "ō", = "o", = "ā", = "ī", = "ū",
= "r̥", = "r̥̄", = "ai", = "au", = "ě", = "ě", = "ǒ", = "â", = "ê", = "ô",
-- vowel signs
= "a", = "i", = "u", = "ē", = "e", = "ō", = "ā", = "ī", = "ū", = "ö", = "ë",
= "r̥", = "r̥̄", = "ai", = "au", = "ě", = "ǒ", = "o", = "ä", = "ê", = "ô",
= "²", = "²",
= "ô",
= "̃", -- chandrabindu
= "̃", -- anusvara
= "ḥ", -- visarga
= "", -- virama
= "ōm̐", -- 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, = true, = 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)
return (((match(first, '') and match(second, '्') and not perm_cl)
or match(first .. second, 'य'))
and 'a' or "") .. 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")
text = gsub(text, "इऺ", "ï" )
text = gsub(text, "उऺ", "ü" )
text = gsub(text, "ॳ", "â" )
text = gsub(text, "अ꣱", "ô")
end
text = gsub(text, ".़?", conv)
text = gsub(text, "ā()̃", "ā͠%1")
text = gsub(text, "uu", "u")
text = gsub(text, "()â", "%1")
text = gsub(text, "()ᵊ", "%1")
text = gsub(text, "aᵊ", "ᵊ")
text = gsub(text, "()a", "%1")
text = gsub(text, "aâ", "â")
text = gsub(text, "ii", "i")
text = gsub(text, "()a", "%1")
text = gsub(text, "i$", "ɨ")
text = gsub(text, "u$", "ʉ")
text = gsub(text, "ᵊ$", "ᵊ̆")
text = gsub(text, "", "")
return mw.ustring.toNFC(text)
end
return export