Module:Sidd-translit

From Wiktionary, the free dictionary
Jump to navigation Jump to search

This module will transliterate text in the Siddham script. It is used to transliterate Apabhramsa, Kamarupi Prakrit, 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:Sidd-translit/testcases.

Functions

[edit]
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 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',  ['๐‘–ฟ']='',

	-- For Japanese Siddham, these alternate vowel signs are the 'warbler' forms while the regular vowel signs are the 'cloud' forms.

	['๐‘—œ'] = '', -- Alternate Vowel Sign U
	['๐‘—'] = '', -- Alternate Vowel Sign UU

}

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    
	['๐‘–พ']='แธฅ',
	--numerals
	--punctuation        
    ['๐‘—ƒ']='.', --double danda
	['๐‘—‚']='.', --danda
    --reconstructed
    ['*'] = '',
}

function export.tr(text, lang, sc)
	text = 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