Module:Sind-translit

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

This module will transliterate text in the Khudabadi script. It is used to transliterate Kachchi and Sindhi. 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:Sind-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', ['๐‘Šฝ']='g', ['๐‘Šพ']='gh', ['๐‘Šฟ']='แน…', 
	['๐‘‹€']='c', ['๐‘‹']='ch', ['๐‘‹‚']='j', ['๐‘‹ƒ']='jฬ„', ['๐‘‹„']='jh', ['๐‘‹…']='รฑ', 
	['๐‘‹†']='แนญ', ['๐‘‹‡']='แนญh', ['๐‘‹ˆ']='แธ', ['๐‘‹‰']='แธฬ ', ['๐‘‹Š']='แน›',['๐‘‹‹']='แธh', ['๐‘‹Œ']='แน‡', 
	['๐‘‹']='t', ['๐‘‹Ž']='th', ['๐‘‹']='d', ['๐‘‹']='dh', ['๐‘‹‘']='n', 
	['๐‘‹’']='p', ['๐‘‹“']='ph', ['๐‘‹”']='b', ['๐‘‹•']='แธ‡', ['๐‘‹–']='bh', ['๐‘‹—']='m', 
	['๐‘‹˜']='y', ['๐‘‹™']='r', ['๐‘‹š']='l', ['๐‘‹›']='v', ['๐‘‹œ']='ล›', 
	['๐‘‹']='s', ['๐‘‹ž']='h', 

--consonants with nukta
	["๐‘Šบ๐‘‹ฉ"] = "q",
	["๐‘Šป๐‘‹ฉ"] = "x",
	["๐‘Šผ๐‘‹ฉ"] = "ฤก",
	["๐‘‹‚๐‘‹ฉ"] = "z",
	["๐‘‹‹๐‘‹ฉ"] = "แน›h",
	["๐‘‹“๐‘‹ฉ"] = "f",
}

local diacritics = {
	['๐‘‹ ']= 'ฤ', ['๐‘‹ก']='i', ['๐‘‹ข']='ฤซ', ['๐‘‹ฃ']='u', ['๐‘‹ค']='ลซ',
	['๐‘‹ฅ']='e', ['๐‘‹ฆ']='ai', ['๐‘‹ง']='o', ['๐‘‹จ']='au', ['๐‘‹ช']='', 
}

local nonconsonants = {
	-- vowels
	['๐‘Šฐ']='a', ['๐‘Šฑ']='ฤ', ['๐‘Šฒ']='i', ['๐‘Šณ']='ฤซ', ['๐‘Šด']='u', ['๐‘Šต']='ลซ', 
	['๐‘Šถ']='e', ['๐‘Šท']='ai', ['๐‘Šธ']='o',['๐‘Šน']='au',
	-- other symbols
	['๐‘‹Ÿ']='แน', -- anusvara
	['๐‘‹ฉ']='.', -- nukta
	-- digits
	['๐‘‹ฐ'] = '0', ['๐‘‹ฑ'] = '1', ['๐‘‹ฒ'] = '2', ['๐‘‹ณ'] = '3', ['๐‘‹ด'] = '4',
	['๐‘‹ต'] = '5', ['๐‘‹ถ'] = '6', ['๐‘‹ท'] = '7', ['๐‘‹ธ'] = '8', ['๐‘‹น'] = '9',
}

local nasal_assim = {
	["[kg]h?"] = "แน…",
	["[cj]h?"] = "รฑ",
	["[แนญแธ]h?"] = "แน‡",
	["[td]h?"] = "n",
	["[pb]h?"] = "m",
	["n"] = "n",
	["m"] = "m",
    ["s"] = "n",
}

-- translit any words or phrases
function export.tr(text, lang, sc)
	local nukta = "([๐‘Šป๐‘Šผ๐‘‹‚๐‘‹“]๐‘‹ฉ)"
	text = mw.ustring.gsub(
		text,
		'([๐‘Šบ๐‘Šป๐‘Šผ๐‘Šฝ๐‘Šพ๐‘Šฟ๐‘‹€๐‘‹๐‘‹‚๐‘‹ƒ๐‘‹„๐‘‹…๐‘‹†๐‘‹‡๐‘‹ˆ๐‘‹‰๐‘‹Š๐‘‹‹๐‘‹Œ๐‘‹๐‘‹Ž๐‘‹๐‘‹๐‘‹‘๐‘‹’๐‘‹“๐‘‹”๐‘‹•๐‘‹–๐‘‹—๐‘‹˜๐‘‹™๐‘‹š๐‘‹›๐‘‹œ๐‘‹๐‘‹ž][๐‘‹ฉ]?)'..
		'([๐‘‹ ๐‘‹ก๐‘‹ข๐‘‹ฃ๐‘‹ค๐‘‹ฅ๐‘‹ฆ๐‘‹ง๐‘‹จ๐‘‹ช]?)',
		function(c, d)
			-- mw.log('match', c, d)
			c = consonants[c] or c
			if d == "" then        
				return c .. 'a'
			else
				return c .. (diacritics[d] or d)
			end
		end)
	
	text = mw.ustring.gsub(text,nukta,consonants)
	text = mw.ustring.gsub(text, '.', nonconsonants)
	for key,val in pairs(nasal_assim) do
		text = mw.ustring.gsub(text,"แน("..key..")",val.."%1")
	end
	text = mw.ustring.gsub(text,"([aiueฤ“oฤฤซลซ])แน ", "%1ฬƒ ")
	text = mw.ustring.gsub(text,"(.?)แน", "%1ฬƒ")
	text = mw.ustring.gsub(text, 'a([iu])ฬƒ', 'aอ %1')

	return mw.ustring.toNFC(text)
end
 
return export