跳转到内容

模組:Sidd-translit

維基詞典,自由的多語言詞典

This module will transliterate text in the 悉曇文字. 它被用於轉寫阿帕布拉姆沙語迦摩縷波普拉克里特語 梵語。 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

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