local export = {}
local consonants = {
['ക']='k', ['ഖ']='kʰ', ['ഗ'] = 'g', ['ഘ'] ='gʱ', ['ങ']='ŋ',
['ച']='t͡ʃ', ['ഛ']='t͡ʃʰ', ['ജ']='d͡ʒ ', ['ഝ']='d͡ʒʱ', ['ഞ']='ɲ',
['ട']='ʈ', ['ഠ']='ʈʰ', ['ഡ']='ɖ', ['ഢ']='ɖʱ', ['ണ']='ɳ',
['ത']='t̪', ['ഥ']='t̪ʰ', ['ദ']=' d̪', ['ധ']=' d̪ʱ', ['ന']='n̪',
['പ']='p', ['ഫ']='f', ['ബ']='b', ['ഭ']='bʱ', ['മ']='m',
['യ']='j', ['ര']='ɾ', ['ല']='l', ['വ']='ʋ',
['ശ']=' ʃ ', ['ഷ']='ʂ', ['സ']='s', ['ഹ']='h',
['ള']='ɭ', ['ഴ']='ɻ', ['റ']='r', ['ഩ']='n', ['ന്റ'] = 'nd', ['ൻ്റ'] = 'nd',
}
local diacritics = {
['ാ']= 'aː', ['ി']='i', ['ീ']='iː', ['ു']='u', ['ൂ']='uː', ['െ']='e',
['േ']='eː', ['ൈ']='ai̯', ['ൊ']='o', ['ോ']='oː', ['ൌ']='au̯', ['ൗ']='au̯',
['്']='', --virama, supresses the inherent vowel "a"
-- no diacritic
[''] = 'a'
}
local nonconsonants = {
-- independent vowels
['അ']='a', ['ആ']='aː', ['ഇ']='i', ['ഈ']='iː', ['ഉ']='u', ['ഊ']='uː',
['എ']='e', ['ഏ']='eː', ['ഐ']='ai̯', ['ഒ']='o', ['ഓ']='oː', ['ഔ']='au̯',
}
local adjust1 = {
['ŋk']='ŋɡ', ['ɲt͡ʃ']='ɲd͡ʒ', ['ɳʈ']='ɳɖ', ['rr']= 'tt', ['n̪t̪']='n̪d̪', ['mp']='mb',
['([aeiou]ː?)k([aeiou])']='%1ɡ%2', ['([aeiou]ː?)t͡ʃ ([aeiou])']='%1d͡ʒ%2',
['([aeiou]ː?)ʈ([aeiou])']='%1ɖ%2', ['([aeiou]ː?)t̪([aeiou])']='%1d̪%2', ['([aeiou]ː?)p([aeiou])']='%1b%2',
}
function export.to_IPA(text)
text = mw.ustring.gsub(
text,
'([ക-ഹ])([ാ-◌്]?)',
function(c, d)
return (consonants[c] or c) .. (diacritics[d])
end)
text = mw.ustring.gsub(text, '[അ-ഔ]', nonconsonants)
for k, v in pairs(adjust1) do
text = mw.ustring.gsub(text, k, v)
text = mw.ustring.gsub(text, k, v) --twice
end
--convert consonant gemination to triangular colon
text = mw.ustring.gsub(text, "([kŋɲʈɳpmjʋɻɭrnɕʂshfzx])%1", "%1ː")
text = mw.ustring.gsub(text, "([tnɾl]̪)%1", "%1ː")
text = mw.ustring.gsub(text, "([td]͡[ʃʒ])%1", "%1ː")
--if an independent vowel is after another vowel, assume diphthong
text = mw.ustring.gsub(text, "([aeiou]ː?)•", "%1")
text2 = text --phonetic
--[=[for k, v in pairs(adjust2) do
text2 = mw.ustring.gsub(text2, k, v)
end]=]
return (text == text2 and { text } or { text, text2 })
end
function export.show(frame)
local args = frame:getParent().args
local page_title = mw.title.getCurrentTitle().text
local text = args[1] or page_title
local qualifier = args['q'] or nil
local transcriptions = export.to_IPA(text)
local IPA_text
if not transcriptions[2] then
IPA_text = require('Module:IPA').format_IPA_full(
require('Module:languages').getByCode('ml'),
{ { pron = '/' .. transcriptions[1] .. '/' } })
else
IPA_text = require('Module:IPA').format_IPA_full(
require('Module:languages').getByCode('ml'),
{ { pron = '/' .. transcriptions[1] .. '/' }, { pron = '[' .. transcriptions[2] .. ']' } })
end
return '* ' .. (qualifier and require("Module:qualifier").format_qualifier{qualifier} .. ' ' or '')
.. IPA_text
end
return export