-- Transliteration for Nepali
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', = 'w', = 'ḷ',
= 'ś', = 'ṣ', = 's', = 'h',
= 'q', = 'x', = 'ġ', = 'v', = 'ḻ',
= 'z', = 'ž', = 'ṛ', = 'ṛh',
= 'f', = 'θ', = 'ṉ', = 'ṟ',
= "'",
-- vowel diacritics
= 'i', = 'u', = 'e', = 'o',
= 'ā', = 'ī', = 'ū',
= 'ŕ',
= 'ai', = 'au',
= 'ŏ',
= 'ĕ',
-- vowel signs
= 'a', = 'i', = 'u', = 'e', = 'o',
= 'ā', = 'ī', = 'ū',
= 'ŕ',
= 'ai', = 'au',
= 'ŏ',
= 'ĕ',
-- chandrabindu
= '̃',
-- anusvara
= '̃',
-- visarga
= 'ḥ',
-- virama
= '',
-- om
= 'oṁ',
-- numerals
= '0', = '1', = '2', = '3', = '4', = '5', = '6', = '7', = '8', = '9',
-- punctuation
= '.', -- danda
= '', -- compound separator
}
local all_cons, special_cons = 'कखगघङचछजझञटठडढतथदधपफबभशषसयरलवहणनम', 'यरलवहनम'
local vowel = 'aिुृेोाीूैौॉॅ'
function export.tr(text, lang, sc, reduction)
text = gsub(
text,
'(़?)(?)',
function(c, d)
return c .. ( d == "" and 'a' or d )
end
)
if reduction and not match(text, "") then
for word in mw.ustring.gmatch(text, "+") do
text = gsub(text, word, "<" .. word .. ">")
end
end
for word in mw.ustring.gmatch(text, "<+>") do
local orig_word = word
word = gsub(word, "", "")
word = gsub(
word,
'(.?)(.)()(़?)a$',
function(pre, first, second, opt)
local last = ""
if match(second, '') and match(first, '्') or
match(second .. first, 'य') or
pre == second and first == "्" then
last = 'a'
end
return pre .. first .. second .. opt .. last
end
)
text = gsub(text, orig_word, word)
end
text = gsub(text, ".़?", conv)
text = gsub(text, "", "")
return mw.ustring.toNFC(text)
end
return export