Module:Mult-translit

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

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