This module will transliterate Sinhalese language text per WT:SI TR. It is also used to transliterate Pali and Sanskrit.
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:si-translit/testcases.
tr(text, lang, sc)
text
written in the script specified by the code sc
, and language specified by the code lang
.nil
.</noinclude>local m_str_utils = require("Module:string utilities")
local gsub = m_str_utils.gsub
local u = m_str_utils.char
local export = {}
local consonants = {
='k' , ='kh' , ='g' , ='gh' , ='ṅ' , ='ⁿg' , ='c' , ='ch' , ='j' , ='jh' ,
='ñ' , ='gn' , ='ⁿj' , ='ṭ' , ='ṭh' , ='ḍ' , ='ḍh' , ='ṇ' , ='ⁿḍ' ,
='t' , ='th' , ='d' , ='dh' , ='n' , ='ⁿd' ,
='p' , ='f' , ='ph' , ='b' , ='bh' , ='m' , ='ᵐb' , ='y' , ='r' , ='l' , ='w' ,
='ś' , ='ṣ' , ='s' , ='h' , ='ḷ' , ='f'
}
local diacritics = {
= 'ā',
= 'æ',
= 'ǣ',
= 'i',
= 'ī',
= 'u',
= 'ū',
= 'e',
= 'ē',
= 'ai',
= 'o',
= 'ō',
= 'au',
= 'r̥',
= 'l̥',
= 'r̥̄',
= 'l̥̄',
= ''
}
local tt = {
-- vowels
='a' , ='ā' , ='æ' , ='ǣ' , ='i' , ='ī' , ='u' , ='ū' ,
='e' , ='ē' , ='ai' , ='o' , ='ō' , ='au' ,
='r̥' , ='r̥̄' , ='l̥' , ='l̥̄' ,
-- other symbols
='ṁ' , -- anusvara
='ḥ' , -- visarga
='' , --hal kirīma, suppresses the inherent vowel "a"
-- punctuation
='.' , -- kunddaliya (obsolete)
}
-- translit any words or phrases
function export.tr(text, lang, sc)
if type(text) == 'table' then
text = text.args
lang = text.args
sc = text.args
end
if (lang == 'sa' or lang == 'pi') then
text=string.gsub(text, 'ඥ', 'ජ්ඤ')
end
text = gsub(text, -- Handle conjunct and touching clusters.
'',
{ = u(0x0dca), = u(0x0dca)})
text = gsub(
text,
'()'..
'(?)',
function(c, d)
if d == "" then
return consonants .. 'a'
else
return consonants .. diacritics
end
end)
text = gsub(text, '.', tt)
if (lang == 'pi' or lang =='sa') then -- Convert to IAST.
text = gsub(text, '.'..u(0x325)..'?'..u(0x304)..'?',
{ = 'ṃ', = 'v', = 'ṛ', ='ṝ', ='ḷ', ='ḹ'})
end
return text
end
return export