Module:Shrd-translit
Jump to navigation
Jump to search
- The following documentation is located at Module:Shrd-translit/documentation. [edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
This module will transliterate text in the Sharada script. It is used to transliterate Apabhramsa, Kashmiri, and Sanskrit.
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:Shrd-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 m_str_utils = require("Module:string utilities")
local gsub = m_str_utils.gsub
local match = m_str_utils.match
local toNFC = mw.ustring.toNFC
local u = m_str_utils.char
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 diatrema = {
['𑆅']='ï', ['𑆇']='ü',
}
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
['*'] = '',
}
function export.tr(text, lang, sc)
text = mw.ustring.gsub(
text,
'([𑆑𑆒𑆓𑆔𑆕𑆖𑆗𑆘𑆙𑆚𑆛𑆜𑆝𑆞𑆟𑆠𑆡𑆢𑆣𑆤𑆥𑆦𑆧𑆨𑆩𑆪𑆫𑆬𑆮𑆭𑆯𑆰𑆱𑆲])'..
'([𑆳𑆴𑆵𑆶𑆷𑆸𑆹𑆺𑆻𑆼𑆽𑆾𑆿𑇀]?)'..
'([𑆅𑆇]?)',
function(c, d, e)
if d == "" and e ~= "" then
return consonants[c] .. 'a' .. diatrema[e]
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)
-- Adjacent vowel letters needing dieresis
text = gsub(text, '([𑆃])([𑆅𑆇])', function(a, b) return tt[a]..diatrema[b] end)
text = gsub(text, '.', tt)
return text
end
return export