Module:Mult-translit

Definition from Wiktionary, the free dictionary
Jump to navigation Jump to search

This module will transliterate text in the Multani script. It is used to transliterate Saraiki.

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:Mult-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 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', ['๐‘Šฆ']='h', 
	['๐‘Š']='วฐ', ['๐‘Š“']='แธ', ['๐‘Šง'] = 'แน›', ['๐‘Šจ'] = 'แน›h', 
}

local nonconsonants = {
	-- vowels
	['๐‘Š€']='a', ['๐‘Š']='i', ['๐‘Š‚']='u', ['๐‘Šƒ']='e', 

	-- other symbols
	['๐‘Šฉ']='.', -- section mark

	-- digits
	['เฉฆ'] = '0', ['เฉง'] = '1', ['เฉจ'] = '2', ['เฉฉ'] = '3', ['เฉช'] = '4',
	['เฉซ'] = '5', ['เฉฌ'] = '6', ['เฉญ'] = '7', ['เฉฎ'] = '8', ['เฉฏ'] = '9',
}

-- translit any words or phrases
function export.tr(text, lang, sc)
	text = mw.ustring.gsub(
		text,
		'([๐‘Š„๐‘Š…๐‘Š†๐‘Šˆ๐‘ŠŠ๐‘Š‹๐‘ŠŒ๐‘Š๐‘Š๐‘Š‘๐‘Š’๐‘Š”๐‘Š•๐‘Š–๐‘Š—๐‘Š˜๐‘Š™๐‘Šš๐‘Š›๐‘Šœ๐‘Š๐‘ŠŸ๐‘Š ๐‘Šก๐‘Šข๐‘Šฃ๐‘Šค๐‘Šฅ๐‘Šฆ๐‘Š๐‘Š“๐‘Šง๐‘Šจ])',
		function(c, d)
			-- mw.log('match', c, d)
			return (consonants[c] or c)
		end)
	
	text = mw.ustring.gsub(text, '.', nonconsonants)
	
	return text
end
 
return export