Module:ml-translit
- The following documentation is located at Module:ml-translit/documentation. [edit] Categories were auto-generated by Module:module categorization. [edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
This module will transliterate Malayalam language text. It is also used to transliterate Badaga, Bellari, Beary, Kodava, Kurichiya, Konkani, Malavedan, Mannan, Tulu, Muduga, and Ravula.
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:ml-translit/testcases.
Functions
tr(text, lang, sc)
- Transliterates a given piece of
text
written in the script specified by the codesc
, and language specified by the codelang
. - When the transliteration fails, returns
nil
.
local export = {}
local consonants = {
['ക']='k', ['ഖ']='kh', ['ഗ']='g', ['ഘ']='gh', ['ങ']='ṅ',
['ച']='c', ['ഛ']='ch', ['ജ']='j', ['ഝ']='jh', ['ഞ']='ñ',
['ട']='ṭ', ['ഠ']='ṭh', ['ഡ']='ḍ', ['ഢ']='ḍh', ['ണ']='ṇ',
['ത']='t', ['ഥ']='th', ['ദ']='d', ['ധ']='dh', ['ന']='n',
['പ']='p', ['ഫ']='ph', ['ബ']='b', ['ഭ']='bh', ['മ']='m',
['യ']='y', ['ര']='r', ['ല']='l', ['വ']='v',
['ശ']='ś', ['ഷ']='ṣ', ['സ']='s', ['ഹ']='h',
['ള']='ḷ', ['ഴ']='ḻ', ['റ']='ṟ', ['ഩ']='ṉ', ['ഺ']='ṯ',
}
local diacritics = {
['\224\181\129\224\181\141'] = 'ŭ',
['\224\180\190'] = 'ā' ,
['\224\180\191'] = 'i' ,
['\224\181\128'] = 'ī' ,
['\224\181\129'] = 'u' ,
['\224\181\130'] = 'ū' ,
['\224\181\131'] = 'r̥' ,
['\224\181\132'] = 'r̥̄' ,
['\224\181\134'] = 'e' ,
['\224\181\135'] = 'ē' ,
['\224\181\136'] = 'ai',
['\224\181\138'] = 'o' ,
['\224\181\139'] = 'ō' ,
['\224\181\140'] = 'au', --archaic au
['\224\181\151'] = 'au',
['\224\181\162'] = 'l̥',
['\224\181\163'] = 'l̥̄' ,
--virama, supresses the inherent vowel "a"
['\224\181\141'] = '',
-- no diacritic
[''] = 'a'
}
local nonconsonants = {
-- vowels
['അ']='a' , ['ആ']='ā' , ['ഇ']='i' , ['ഈ']='ī' , ['ഉ']='u' , ['ഊ']='ū' ,
['ഋ']='r̥' , ['ൠ']='r̥̄' , ['ഌ']='l̥' , ['ൡ']='l̥̄', ['എ']='e' , ['ഏ']='ē' ,
['ഐ']='ai' , ['ഒ']='o' , ['ഓ']='ō' , ['ഔ']='au' , ['ൟ']='ī' ,
-- other symbols
['ം']='ṁ', -- anusvara
['ഃ']='ḥ' , -- visarga
['ഽ']='’', -- praślēṣam
-- chillus, consonants that never take vowels
['ൺ']='ṇ' , ['ൻ']='ṉ' , ['ർ']='ṟ' , ['ൽ']='l' , ['ൾ']='ḷ' , ['ൿ']='k' , ['ൔ']='m', ['ൕ']='y', ['ൖ']='ḻ',
['ൎ']='ṟ',
-- digits
['൦'] = '0', ['൧'] = '1', ['൨'] = '2', ['൩'] = '3', ['൪'] = '4',
['൫'] = '5', ['൬'] = '6', ['൭'] = '7', ['൮'] = '8', ['൯']= '9',
['൰']='10', ['൱']='100', ['൲']='1000',
['൳']='¼', ['൴']='½', ['൵']='¾', ['൞']='⅕', ['൷']='⅛',
['൜']='⅒', ['൶']='¹⁄₁₆', ['൸']='3⁄16', ['൛']='1⁄20',
['൝']='3⁄20', ['൙']='1⁄40', ['൚']='3⁄80', ['൘']='1⁄160',
}
-- translit any words or phrases
function export.tr(text, lang, sc)
local VIRAMA = '്'
-- final virama rules
if lang == "ml" or "tcy" then
text = mw.ustring.gsub(text, VIRAMA .. "([%,%.%!%?%:%;]?)$", VIRAMA .. "ŭ%1")
text = mw.ustring.gsub(text, VIRAMA .. "([%,%.%!%?%:%;]?) ", VIRAMA .. "ŭ%1 ")
end
text = mw.ustring.gsub(
text,
'([കഖഗഘങചഛജഝഞടഠഡഢണതഥദധനപഫബഭമയരലവശഷസഹളഴറഩഺ])'..
'(\224\181\129?[\224\180\190\224\180\191\224\181\128\224\181\129\224\181\130\224\181\131\224\181\132\224\181\162\224\181\163\224\181\134\224\181\135\224\181\138\224\181\139\224\181\140\224\181\136\224\181\151\224\181\141]?)',
function(c, d)
return consonants[c] .. (diacritics[d] or d)
end)
text = mw.ustring.gsub(text, '.', nonconsonants)
-- anusvara
text = mw.ustring.gsub(text, 'ṁ([kgṅ])', 'ṅ%1')
text = mw.ustring.gsub(text, 'ṁ([cjñ])', 'ñ%1')
text = mw.ustring.gsub(text, 'ṁ([ṭḍṇ])', 'ṇ%1')
text = mw.ustring.gsub(text, 'ṁ([tdn])', 'n%1')
text = mw.ustring.gsub(text, 'ṁ([pbm])', 'm%1')
text = mw.ustring.gsub(text, "ŭ ([%,%.%!%?%:%;]?)([aāiīuūeo])", " %1%2") -- ŭ is elided before vowels
return text
end
return export