This module will transliterate text in the Kharoshthi script. It is used to transliterate Ashokan Prakrit, Gandhari, and Niya Prakrit.
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:Khar-translit/testcases.
tr(text, lang, sc)
text
written in the script specified by the code sc
, and language specified by the code lang
.nil
.local export = {}
local u = require("Module:string/char")
local gsub = mw.ustring.gsub
local consonants = {
--defer transliteration of null consonant.
= '𐨀',
--consonants
='k', ='kh', ='g', ='gh',
='c', ='ch', ='j', ='ñ',
='ṭ', ='ṭh', ='ḍ', ='ḍh', ='ṇ',
='t', ='th', ='d', ='dh', ='n',
='p', ='ph', ='b', ='bh', ='m',
='y', ='r', ='l', ='v',
='ś', ='ṣ', ='s', ='z', ='h',
='ḱ', ='ṭ́h', ='ṭ́', ='vh',
}
local diacritics = {
--matras
='i', ='u', ='ṛ',
='e', ='o', ='ā',
='ī', ='ū', ='ṝ',
='ai', ='au', ='', ='Ⓙ',
= 'a͚', = 'u͚', ='◌́',
}
local tt = {
--vowels
= '',
-- anusvara
='ṃ', --until a better method is found
-- visarga
='ḥ',
--numerals
='1', ='2', ='3', ='4',
='10', ='20', ='100', ='1000',
--punctuation
='.', --danda
='.', --double danda
}
function export.tr(text, lang, sc)
local failed = nil
if sc ~= "Khar" then
return nil
end
-- Consonants appear as part of sequences canonically equivalent to consonant+nukta+vowel, so
-- allowing for multiplicity and the string being normalised (by Wikimedia policy), the matching
-- RE is:
local form = '()(𐨹?)(?𐨿?)(𐨺?)(𐨍?)(𐨸?)(??𐨌?𐨍?)'
text = gsub(text, form, function(c, n1, h, n2, vi, n3, vm)
local d = h..vi..vm -- Expect at most one catenand to be non-empty.
local cdia = ''
local cons = consonants
local retval
if n1 ~= '' then -- Cauda
if cons == 's' or cons == 'ś' then
cdia = cdia .. u(0x0331) -- Combining macron below
else
cdia = cdia .. u(0x0301) -- Combining acute
end
end
if n2 ~= '' then cdia = cdia .. u(0x0323) end -- Combining dot below
if n3 ~= '' then cdia = cdia .. u(0x0304) end -- Combining macron
if d == "" then
retval = cons .. cdia .. 'a'
else
local dia = diacritics
if not dia then
mw.addWarning('Failed to transliterate 𐨀' .. d .. ' in ' .. text)
failed = true
dia = 'D'
end
retval = cons .. cdia .. dia
end
return mw.ustring.toNFD(retval)
end)
text = gsub(text, "(a)𐨀()", "%1%2"..u(0x308)) -- Apply diaeresis
text = gsub(text, '.', tt)
text = gsub(text, 'lⒿy', 'lý')
text = gsub(text, 'Ⓙ', '')
text = gsub(text, u(0x301, 0x304), u(0x304, 0x301))
if failed then return nil end
return mw.ustring.toNFC(text)
end
return export