વિભાગ:sa-translit
Appearance
This module will transliterate સંસ્કૃત ભાષા text.
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:ભાષાઓ#ભાષા:લિપ્યંતરણ.
For testcases, see Module:sa-translit/કસોટીચકાસણીઓ.
Functions
[ફેરફાર કરો]tr(લખાણ, ભાષા, લિપિ)
- Transliterates a given piece of
લખાણext
written in the script specified byલિપિ
, and language specified bylang
. When the transliteration fails, returnsnil
.
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 = {
['ा']='ā', ['ि']='i', ['ी']='ī', ['ु']='u', ['ू']='ū', ['ृ']='ṛ', ['ॄ']='ṝ',
['ॢ']='ḷ', ['ॣ']='ḹ', ['े']='e', ['ै']='ai', ['ो']='o', ['ौ']='au', ['्']='',
}
local tt = {
-- vowels
['अ']='a', ['आ']='ā', ['इ']='i', ['ई']='ī', ['उ']='u', ['ऊ']='ū', ['ऋ']='ṛ', ['ॠ']='ṝ',
['ऌ']='ḷ', ['ॡ']='ḹ', ['ए']='e', ['ऐ']='ai', ['ओ']='o', ['औ']='au',
-- chandrabindu
['ँ']='m̐', --until a better method is found
-- anusvara
['ं']='ṃ', --until a better method is found
-- visarga
['ः']='ḥ',
-- avagraha
['ऽ']='ʼ',
--numerals
['०']='0', ['१']='1', ['२']='2', ['३']='3', ['४']='4', ['५']='5', ['६']='6', ['७']='7', ['८']='8', ['९']='9',
--punctuation
['॥']='.', --double danda
['।']='.', --danda
--Vedic extensions
['ᳵ']='x', ['ᳶ']='f',
--Om
['ॐ']='oṃ',
--reconstructed
['*'] = '',
--accentuation (needs to be handled)
['॑'] = '', ['॒'] = ''
}
function export.tr(text, lang, sc)
if sc ~= "Deva" then
return nil
end
text = mw.ustring.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] .. '̈'
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)
text = mw.ustring.toNFC(text)
return text
end
return export