Module:tevo-translit
- The following documentation is generated by Module:documentation/functions/translit. [edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
This module will transliterate Ancient Tevvic language text. It is also used to transliterate Middle Tevvic and Tevvic.
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:tevo-translit/testcases.
Functions
tr(text, lang, sc)- Transliterates a given piece of
textwritten in the script specified by the codesc, and language specified by the codelang. - When the transliteration fails, returns
nil.
local export = {}
local m_str_utils = require("Module:string utilities")
local gsub = m_str_utils.gsub
local toNFC = mw.ustring.toNFC
local U = m_str_utils.char
local grave = U(0x300)
local acute = U(0x301)
local diaeresis = U(0x308)
local svar = U(0x951)
local anud = U(0x952)
local d_svar = U(0x1CDA) -- double svarita, sometimes used for long vowel with svarita
local consonants = {
['क']='k',
['ख']='kh',
['ग']='g',
['घ']='gh',
['च']='c',
['छ']='ch',
['ज']='j',
['झ']='jh',
['ञ']='ñ',
['श']='ś',
['झ़']='ź',
['ट']='ṭ',
['ठ']='ṭh',
['ड']='ḍ',
['ढ']='ḍh',
['ण']='ṇ',
['ष']='ṣ',
['ढ़']='ẓ',
['त']='t',
['थ']='th',
['द']='d',
['ध']='dh',
['न']='n',
['स']='s',
['ज़']='z',
['प']='p',
['फ']='ph',
['ब']='b',
['भ']='bh',
['म']='m',
['य']='y',
['र']='r',
['ल']='l',
['व']='v',
['ह']='h',
}
local diacritics = {
['ा']='ā',
['ि']='i',
['ी']='ī',
['ु']='u',
['ू']='ū',
['ॆ']='ei',
['े']='ēi',
['ॅ']='e',
['ै']='ē',
['ॊ']='ou',
['ो']='ōu',
['ॉ']='o',
['ौ']='ō',
['्']='',
}
local tt = {
-- vowels
['अ']='a',
['आ']='ā',
['इ']='i',
['ई']='ī',
['उ']='u',
['ऊ']='ū',
['ऎ']='ei',
['ए']='ēi',
['ऍ']='e',
['ऐ']='ē',
['ऒ']='ou',
['ओ']='ōu',
['ऑ']='o',
['औ']='ō',
-- anusvara
['ं']='̣',
-- visarga
['ः']='h',
-- avagraha
['ऽ']='ʼ',
--numerals
['०']='0', ['१']='1', ['२']='2', ['३']='3', ['४']='4', ['५']='5', ['६']='6', ['७']='7', ['८']='8', ['९']='9',
['॔']='́',
['॓']='́',
--punctuation
-- ['॥']='.', --double danda
-- ['।']='.', --danda
--Om
['ॐ']='oṃ',
--reconstructed
-- ['*'] = '',
}
function export.tr(text, lang, sc)
if sc ~= "Deva" then
return nil
end
text = gsub(
text,
'([क-ह]?)'..
'([ािीुूृॄॢॣेैोौ्ॅॆॊॉ]?)'..
'([अ-औ]?)',
function(c, d, e)
if d == "" and e ~= "" then
if tt[e] == "i" or tt[e] == "u" then return consonants[c] .. 'a' .. tt[e] .. diaeresis
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 = gsub(text, '([aअ][' .. acute .. grave .. ']?[इउ])', '%1' .. diaeresis)
text = gsub(text, '.', tt)
text = gsub(text, 'a([iu])([' .. acute .. grave .. '])', 'a%2%1')
text = gsub(text, " ?[।॥]", ".")
text = gsub(text, "(ā" .. acute .. "3[iu])" .. acute, "%1") -- for pluti vowels
text = toNFC(text)
return text
end
return export