Module:Khar-translit

Hello, you have come here looking for the meaning of the word Module:Khar-translit. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:Khar-translit, but we will also tell you about its etymology, its characteristics and you will know how to say Module:Khar-translit in singular and plural. Everything you need to know about the word Module:Khar-translit you have here. The definition of the word Module:Khar-translit will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:Khar-translit, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

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.

Functions

tr(text, lang, sc)
Transliterates a given piece of text written in the script specified by the code sc, and language specified by the code lang.
When the transliteration fails, returns 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