This module will transliterate Newar 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:new-Newa-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 Newar in Newa script
local export = {}
local gsub = mw.ustring.gsub
local match = mw.ustring.match
local conv = {
-- consonants
= 'k', = 'kh', = 'g', = 'gh', = 'ṅ', = 'ṅh',
= 'c', = 'ch', = 'j', = 'jh', = 'ñ', = 'ñh',
= 'ṭ', = 'ṭh', = 'ḍ', = 'ḍh', = 'ṇ',
= 't', = 'th', = 'd', = 'dh', = 'n', ='nh',
= 'p', = 'ph', = 'b', = 'bh', = 'm', ='mh',
= 'y', = 'r', = 'rh', = 'l', = 'lh', = 'w', = 'ś', = 'ṣ', = 's', = 'h',
-- vowel diacritics
= 'i', = 'u', = 'e', = 'o', = 'ā', = 'ī', = 'ū', = 'r̥', = 'r̥̄', = 'l̥', = 'l̥̄', = 'ai', = 'au',
-- vowels
= 'a', = 'i', = 'u', = 'e', = 'o', = 'ā', = 'ī', = 'ū', = 'r̥', = 'r̥̄', = 'l̥', = 'l̥̄', = 'ai', = 'au',
-- chandrabindu
= '̃',
-- anusvara
= 'ṃ', = 'ṃ',
-- visarga
= 'ḥ',
-- nuqta
= '',
-- virama
= '',
-- om
= 'om',
-- avagraha
='’',
-- numerals
= '0', = '1', = '2', = '3', = '4', = '5', = '6', = '7', = '8', = '9',
-- punctuation
= '.', -- danda
= '.', -- double danda
= '', -- comma
-- abbreviation sign
= '.',
}
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, '𑐫𑑂', 'y') end
text = gsub(text, '.𑑆?', conv)
text = gsub(text, 'a()̃', 'a͠%1')
text = gsub(text, "", "") return mw.ustring.toNFC(text)
end
return export