Module:inc-opa-Guru-translit

This module will transliterate Old Punjabi language text. 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:inc-opa-Guru-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 conv = {
	--consonants without nukta
	["ਸ"] = "s",
	["ਹ"] = "h",
	["ਕ"] = "k", ["ਖ"] = "kh", ["ਗ"] = "g", ["ਘ"] = "gh", ["ਙ"] = "ṅ",
	["ਚ"] = "c", ["ਛ"] = "ch", ["ਜ"] = "j", ["ਝ"] = "jh", ["ਞ"] = "ñ",
	["ਟ"] = "ṭ", ["ਠ"] = "ṭh", ["ਡ"] = "ḍ", ["ਢ"] = "ḍh", ["ਣ"] = "ṇ",
	["ਤ"] = "t", ["ਥ"] = "th", ["ਦ"] = "d", ["ਧ"] = "dh", ["ਨ"] = "n",
	["ਪ"] = "p", ["ਫ"] = "ph", ["ਬ"] = "b", ["ਭ"] = "bh", ["ਮ"] = "m",
	["ਯ"] = "y", ["ਰ"] = "r", ["ਲ"] = "l", 	["ਵ"] = "v", ["ੜ"] = "ṛ",
	
	-- vowels
	["ਾ"] = "ā",
	["ਿ"] = "i", ["ੀ"] = "ī",
	["ੁ"] = "u", ["ੂ"] = "ū",
	["ੇ"] = "e", ["ੈ"] = "ai",
	["ੋ"] = "o", ["ੌ"] = "au",
	
	-- other diacritics
	["ੰ"] = "ṃ", --ṭippi: nasalize
	["ਂ"] = "ṃ", --bindi: nasalize	
	["੍"] = "", --halant, supresses the inherent vowel "a"
	
	-- independent vowels
	["ਅ"] = "a", ["ਆ"] = "ā",
	["ਇ"] = "i", ["ਈ"] = "ī",
	["ਉ"] = "u", ["ਊ"] = "ū",
	["ਏ"] = "e", ["ਐ"] = "ai",
	["ਓ"] = "o", ["ਔ"] = "au",
	
	-- 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 c = "([ਸਹਕਖਗਘਙਚਛਜਝਞਟਠਡਢਣਤਥਦਧਨਪਫਬਭਮਯਰਲਵੜ]਼?)"
	local y = "ਯ"
	local v = "([aਾਿੀੁੂੇੈੋੌ੍])"
	local virama = "੍"
	local n = "([ੰਂ]?)"
	
	local no_virama = mw.ustring.gsub(v,virama,"")
	
	text = text .. " "
	
	text = mw.ustring.gsub(text,c,"%1a")
	text = mw.ustring.gsub(text,"a"..v,"%1")
	
	text = mw.ustring.gsub(text,".",conv)
	
	for key,val in pairs(nasal_assim) do
		text = mw.ustring.gsub(text,"ṃ("..key..")",val.."%1")
	end

	text = mw.ustring.gsub(text," ?[।॥]",".")
	
	text = mw.ustring.gsub(text," $","")
	text = mw.ustring.gsub(text,"hh","h") -- ੍ਹ੍ਹ ਨ੍ਹ੍ਹ
	text = mw.ustring.gsub(text,"yy","y") -- ੍ਯ੍ਯ ਖ੍ਯ੍ਯ
	
	return mw.ustring.toNFC(text)
end
 
return export