Module:tcy-Tutg-translit

From Linguifex
Revision as of 04:41, 12 July 2025 by wikt>Kutchkutch
(diff) โ† Older revisionย | Latest revision (diff)ย | Newer revision โ†’ (diff)
Jump to navigation Jump to search

Documentation for this module may be created at Module:tcy-Tutg-translit/doc

local export = {}
local gsub = mw.ustring.gsub
 
local consonants = {
	['๐‘Ž’'] = 'k', ['๐‘Ž“'] = 'kh', ['๐‘Ž”'] = 'g', ['๐‘Ž•'] = 'gh', ['๐‘Ž–']='แน…',
	['๐‘Ž—'] = 'c', ['๐‘Ž˜'] = 'ch', ['๐‘Ž™'] = 'j', ['๐‘Žš'] = 'jh', ['๐‘Ž›']='รฑ',
	['๐‘Žœ'] = 'แนญ', ['๐‘Ž'] = 'แนญh', ['๐‘Žž'] = 'แธ', ['๐‘ŽŸ'] = 'แธh', ['๐‘Ž ']='แน‡',
	['๐‘Žก'] = 't',  ['๐‘Žข'] = 'th', ['๐‘Žฃ'] = 'd', ['๐‘Žค'] = 'dh', ['๐‘Žฅ']='n',
	['๐‘Žฆ'] = 'p', ['๐‘Žง'] = 'ph', ['๐‘Žจ'] = 'b', ['๐‘Žฉ'] = 'bh' , ['๐‘Žช']='m',
	['๐‘Žซ'] = 'y', ['๐‘Žฌ'] = 'r', ['๐‘‘'] = 'r', ['๐‘Žญ'] = 'l',  ['๐‘Žณ'] = 'แธท', ['๐‘Žฎ'] = 'v',  ['๐‘Žฏ'] = 'ล›',  ['๐‘Žฐ'] = 'แนฃ', ['๐‘Žฑ'] = 's', ['๐‘Žฒ'] = 'h', 
}

local diacritics = {
	['๐‘Žธ'] = 'ฤ', ['๐‘Žน'] = 'i',  ['๐‘Žบ'] =  'ฤซ',['๐‘Žป'] = 'u', ['๐‘Žผ'] = 'ลซ',
	['๐‘Žฝ'] = 'rฬฅ', ['๐‘Žพ'] ='rฬฅฬ„', ['๐‘Žฟ'] ='lฬฅ', ['๐‘€'] = 'lฬฅฬ„', ['๐‘‚'] = 'ฤ“', ['๐‘…'] = 'ai', ['๐‘‡'] = 'ล', ['๐‘ˆ'] = 'au', ['๐‘Ž'] = '', ['๐‘'] = '',
}
local tt = {
	-- vowels
	['๐‘Ž€'] = 'a', ['๐‘ށ'] ='ฤ' , ['๐‘Ž‚'] ='i' , ['๐‘Žƒ'] = 'ฤซ' , ['๐‘Ž„'] = 'u' , ['๐‘Ž…'] = 'ลซ' , 
	['๐‘ކ'] = 'rฬฅ', ['๐‘އ'] ='rฬฅฬ„', ['๐‘Žˆ'] ='lฬฅ', ['๐‘މ'] = 'lฬฅฬ„', ['๐‘Ž‹'] = 'ฤ“', ['๐‘ŽŽ'] ='ai', ['๐‘ސ'] ='ล', ['๐‘Ž‘'] = 'au',
	-- other symbols
	['๐‘Žท'] = 'แน',-- avagraha
	['๐‘Œ'] = 'แน',-- anusvara
	['๐‘'] = 'แธฅ' ,  -- visarga
	['๐‘—'] = 'ลm' , -- om
}

-- translit any words or phrases
function export.tr(text, lang, sc)
	local VIRAMA = '๐‘Ž'
	
	-- final virama rules
	if lang == "tcy" then
		text = gsub(text, VIRAMA .. "([%,%.%!%?%:%;]?)$", VIRAMA .. "ลญ%1")
		text = gsub(text, VIRAMA .. "([%,%.%!%?%:%;]?) ", VIRAMA .. "ลญ%1 ")
	end
	text = gsub(
		text,
		'([๐‘Ž’๐‘Ž“๐‘Ž”๐‘Ž•๐‘Ž–๐‘Ž—๐‘Ž˜๐‘Ž™๐‘Žš๐‘Ž›๐‘Žœ๐‘Ž๐‘Žž๐‘ŽŸ๐‘Ž ๐‘Žก๐‘Žข๐‘Žฃ๐‘Žค๐‘Žฅ๐‘Žฆ๐‘Žง๐‘Žจ๐‘Žฉ๐‘Žช๐‘Žซ๐‘Žฌ๐‘Žญ๐‘Žฎ๐‘Žฏ๐‘Žฐ๐‘Žฑ๐‘Žฒ๐‘Žณ๐‘Žด])'..
		'([๐‘Žธ๐‘Žน๐‘Žบ๐‘Žป๐‘Žผ๐‘Žฝ๐‘Žพ๐‘Žฟ๐‘€๐‘‚๐‘…๐‘‡๐‘ˆ๐‘Ž๐‘]?)',
		function(c, d)
			if d == "" then        
				return consonants[c] ..'a'
			else
				return consonants[c] .. diacritics[d]
			end
		end)
	
	text = gsub(text,'.', tt)
	
	-- anusvara
	text = gsub(text,'แน([kgแน…])','แน…%1')
	text = gsub(text,'แน([cjรฑ])','รฑ%1')
	text = gsub(text,'แน([แนญแธแน‡])','แน‡%1')
	text = gsub(text,'แน([tdn])','n%1')
	text = gsub(text,'แน([pbm])','m%1')
	
	return text
end
 
return export