Module:Cakm-translit
Documentation for this module may be created at Module:Cakm-translit/doc
local export = {}
local u = require("Module:string/char")
-- Stage 1: IAST-style
local consonants = {
--consonants
-- 'โจ' is a convenience for language specific modifications.
['๐']='',
['๐']='k', ['๐']='kh', ['๐']='g', ['๐']='gh', ['๐']='แน
',
['๐']='c', ['๐']='ch', ['๐']='j', ['๐']='jh', ['๐']='รฑ',
['๐']='แนญ', ['๐']='แนญh', ['๐']='แธ', ['๐']='แธh', ['๐']='แน',
['๐']='t', ['๐']='th', ['๐']='d', ['๐']='dh', ['๐']='n',
['๐']='p', ['๐']='ph', ['๐']='b', ['๐']='bh', ['๐']='m',
['๐ ']='y', ['๐ก']='โจ', ['๐ข']='r', ['๐ฃ']='l', ['๐ค']='v', ['๐
']='v',
-- ['๐ฐ']='ล', ['๐ฑ']='แนฃ',
['๐ฅ']='s', ['๐ฆ']='h', ['๐
']='แธท',
}
local diacritics = {
--matras
['๐
']='ฤ', ['๐จ']='i', ['๐ฉ']='ฤซ', ['๐ช']='u', ['๐ซ']='ลซ',
-- ['๐พ']='แน', ['๐ฟ']='แน', ['๐']='lฬฅ', ['๐']='lฬฅฬ',
['๐ฌ']='e', ['๐ญ']='ai', ['๐ฎ']='o', ['๐ฏ']='au', ['๐ด']='', ['๐ณ']='',
-- Oddities
['๐ง']='ฤ', [u(0x11130)]='oi', [u(0x11146)]='ei',
}
local tt = {
--vowels
['๐']='a', ['๐']='i', ['๐
']='u', ['๐']='e',
-- chandrabindu
['๐']='mฬ', --until a better method is found
-- anusvara
['๐']='แน', --until a better method is found
-- visarga
['๐']='แธฅ',
--numerals
['๐ถ']='0', ['๐ท']='1', ['๐ธ']='2', ['๐น']='3', ['๐บ']='4', ['๐ป']='5', ['๐ผ']='6', ['๐ฝ']='7', ['๐พ']='8', ['๐ฟ']='9',
--punctuation
['๐
']='.', --danda
['๐
']='.', --double danda
['๐
']='?', -- question mark
}
function export.tr(text, lang, sc)
if type(lang) == "table" then
lang = lang:getFullCode()
end
text = mw.ustring.gsub(
text,
'([๐๐-๐ฆ๐
๐
])'.. -- consonant
'([๐ง-๐ด'..u(0x11145,0x11146)..']?)'.. -- vowel, joiner or no vowel
'([๐
-๐]?)', -- independent vowel
function(c, d, e)
if d == "" and e ~= "" then
if tt[e] == "i" or tt[e] == "u" then return consonants[c] .. 'a' .. tt[e] .. 'ฬ'
else return consonants[c] .. 'a' .. tt[e] end
elseif e ~= "" then
return consonants[c] .. diacritics[d] .. tt[e]
elseif d == "" then
return consonants[c] .. 'a'
else
return consonants[c] .. diacritics[d]
end
end)
text = mw.ustring.gsub(text, '.', tt)
if (lang == 'ccp') then
text = mw.ustring.gsub(text, '.',
{
['ฤ']='a', ['a']='ฤ', ['ฤ']='A',
-- ['แน']='แน
',
['v']='w',
['y']='แบ' ,['โจ']='y',
})
text = mw.ustring.gsub(text, 'แน$', 'แน
')
elseif (lang == 'pi') then
text = mw.ustring.gsub(text, 'aแธฅ', 'ฤ')
end
if (lang == 'sa' or lang == 'pi') and mw.ustring.match(text, 'lฬฅ') then
text = mw.ustring.gsub(text, 'lฬฅ', 'แธท')
text = mw.ustring.toNFC(text)
end
return text
end
return export