This module will transliterate Sherpa language text.
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:xsr-Deva-translit/testcases.
tr(text, lang, sc)
text
written in the script specified by the code sc
, and language specified by the code lang
.nil
.local export = {}
local gsub = mw.ustring.gsub
local match = mw.ustring.match
local conv = {
-- consonants
= 'k', = 'kh', = 'g', = 'ng',
= 'ts', = 'tsh', = 'dz', = 'ny',
= 'ṭ', = 'ṭh', = 'ḍ',
= 't', = 'th', = 'd', = 'n',
= 'p', = 'ph', = 'b', = 'm',
= 'y', = 'r', = 'l', = 'w', = 'ḷ',
= 'sh', = 's', = 'h',
= 'zh', = 'z', = "'",
= 'c', = 'ch',
--
= 'gh', = 'dzh',
= 'ḍh', = 'ṇ', = 'dh',
= 'bh', = 'ṣ',
= 'q', = 'x', = 'ġ',
= 'ḻ', = 'z', = 'ž',
= 'ṛ', = 'ṛh', = 'f',
= 'θ', = 'ð', = 'ṉ',
= 'ṟ', = 'V',
= 'ž',
-- vowel diacritics
= 'i', = 'u', = 'e', = 'o', = 'ā', = 'ī', = 'ū', = 'r̥', = 'r̥̄', = 'l̥', = 'l̥̄', = 'ai', = 'au', = 'ŏ', = 'ĕ',
-- vowel signs
= 'a', = 'i', = 'u', = 'e', = 'o', = 'ā', = 'ī', = 'ū', = 'r̥', = 'r̥̄', = 'l̥', = 'l̥̄', = 'ai', = 'au', = 'ŏ', = 'ĕ', = 'ĕ',
-- chandrabindu
= '̃',
-- anusvara
= '̃',
-- visarga
= 'ḥ',
-- virama
= '',
-- numerals
= '0', = '1', = '2', = '3', = '4', = '5', = '6', = '7', = '8', = '9',
-- punctuation
= '.', -- danda
= '.', -- double danda
= '', -- compound separator
-- abbreviation sign
= '.',
}
local perm_cl = {
= true,
}
local all_cons, special_cons = 'कखगघङचछजझञटठडढणतथदधनपफबभमयरलवसशषह', 'कखगघचछजझटठडढणतथदधनपफबभमयरलवशषसह'
local vowel, vowel_sign = '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, 'ं')
or match(first, '') and match(second, '्') and not perm_cl)
or match(first .. second, 'य') or match(first .. second, 'ह'))
and 'a' or "") .. opt .. first .. second .. third end)
word = gsub(word, '(.?)ं(.)', function(succ, prev)
return succ .. (succ..prev == "" 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, "च्य", "c")
text = gsub(text, "छ्य", "ch")
text = gsub(text, "ज्य", "j")
text = gsub(text, "झ्य", "jh")
text = gsub(text, "ङ्य", "ny")
text = gsub(text, "श्य", "zh") end
text = gsub(text, '.़?', conv)
text = gsub(text, 'a()̃', 'a͠%1')
text = gsub(text, "", "")
return mw.ustring.toNFC(text)
end
return export