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