Module:Sind-translit

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

This module will transliterate text in the Khudawadi 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', ['π‘‹ˆ']='ḍ', ['𑋉']='dΜ€', ['π‘‹Š']='αΉ›',['π‘‹‹']='ḍh', ['π‘‹Œ']='αΉ‡', 
	['𑋍']='t', ['π‘‹Ž']='th', ['𑋏']='d', ['𑋐']='dh', ['π‘‹‘']='n', 
	['π‘‹’']='p', ['π‘‹“']='ph', ['π‘‹”']='b', ['π‘‹•']='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