This module will transliterate Sanskrit language text per WT:SA 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:sa-Taml-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 function dc(text)
return string.gsub(string.gsub(text, 'க', ''), '𑌕', '') end -- 'drop carrier'
local consonants = {
='k' , ='ṅ' , ='c' , ='ñ' , ='ṭ' , ='ṇ' , ='t' ,
='n' , ='p', ='m' , ='y' , ='r' , ='l' , ='v' ,
='ḻ' , ='ḷ' , ='ṟ' ,
='n' , -- So only contextual distinction between ந and ன.
='ś' , ='j' , ='ṣ' ,
='s' , ='h' ,
-- ='f' , ='z', ='ks' , ='x',
='ḥ' , ='о̄m',
-- Consonants modified by spacing superscript digit. Be liberal.
='k', ='kh', ='g', ='gh',
='c', ='ch', ='j', ='jh',
='j', ='jh',
='ṭ', ='ṭh', ='ḍ', ='ḍh',
='t', ='th', ='d', ='dh',
='p', ='ph', ='b', ='bh',
='ṃ', ='m̐', ='Ⓡ', ='Ⓛ',
-- Consonants modified by spacing subscript digit. Be liberal.
='k', ='kh', ='g', ='gh',
='c', ='ch', ='j', ='jh',
='j', ='jh',
='ṭ', ='ṭh', ='ḍ', ='ḍh',
='t', ='th', ='d', ='dh',
='p', ='ph', ='b', ='bh',
='ṃ', ='m̐', ='Ⓡ', ='Ⓛ',
}
local diacritics = { -- Obliterate Tamil length contrast in mid vowels later.
= 'ā' , ='i' , ='ī' , ='u' , ='ū' , ='e' ,
='ē' , ='ai' , ='o' , ='ō' , ='au',
='', -- pulli, suppresses the inherent vowel "a"
-- Grantha syllabic consonants get used:
='ṛ', ='ṝ', ='ḷ', ='ḹ',
-- no diacritic
= 'a',
}
local nonconsonants = {
-- vowels
='’a' , ='’ā' , ='’i' , ='’ī' , ='’u' , ='’ū' ,
='’e' , ='’ē' , ='’ai' , ='’o' , ='’ō' , ='’au' , ='о̄m',
-- other symbols
='ḥ', = 'ṃ', = 'ḥ',
-- syllabic consonants (Grantha)ː
='ṛ', ='ṝ', ='ḷ', ='ḹ',
}
local syll2 = {
='ṛ', ='ṝ', ='ḷ', ='ḹ',
}
-- translit any words or phrases
function export.tr(text, lang, sc)
-- Special vowel-killing diacritics
local pattern = "" -- gsub on gsub arguments tends to fail!
text = mw.ustring.gsub(text, pattern, {
= "ṃ", -- Desirable to get more and independent examples.
= " ṃ ",
= "y̐", = "l̐", = "v̐",
})
local nukta = '(?)'
local anusvara = dc('(?)')
local vowel = dc('(?)')
text = mw.ustring.gsub(
text,
'(ஃ?)()'..nukta..vowel..nukta..'(?)'..nukta..anusvara..nukta,
function(h, c, n1, d, n2, d2, n3, av, n4)
local cn = c .. n1 .. n2 .. n3 .. n4
local da = d..d2
if d2 ~= "" then da = mw.ustring.toNFC(da) end
return (consonants or (consonants or "") .. (consonants or cn)) ..
(diacritics or da) .. av
end)
text = mw.ustring.gsub(text, '.', nonconsonants)
text = string.gsub(text, 'ē', 'e')
text = string.gsub(text, 'ō', 'o')
text = mw.ustring.gsub(text, '', syll2)
text = string.gsub(text, '^’', '')
text = mw.ustring.gsub(text, '()’', '%1')
return text
end
return export