This module will transliterate text in the Gurmukhi script. It is used to transliterate Punjabi and Pahari-Potwari.
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:Guru-translit/testcases.
tr(text, lang, sc)
text
written in the script specified by the code sc
, and language specified by the code lang
.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", = "ṛ",
--consonants with nukta
= "ś",
= "x",
= "ġ",
= "z",
= "f",
= "ḷ",
= "q",
= "ṛ",
-- vowels
= "ā",
= "i", = "ī",
= "u", = "ū",
= "e", = "ai",
= "o", = "au",
-- other diacritics
= "N", --ṭippi: nasalize
= "N", --bindi: nasalize
= "ː", --addak: geminate
= "", --halant, supresses the inherent vowel "a"
= "h", --voiceless "h" sound (tone raiser)
-- independent vowels
= "a", = "ā",
= "i", = "ī",
= "u", = "ū",
= "ē", = "ai",
= "o", = "au",
-- digits
= "0", = "1", = "2", = "3", = "4",
= "5", = "6", = "7", = "8", = "9",
}
local nasal_assim = {
h?"] = "ṅ",
h?"] = "ñ",
h?"] = "ṇ",
h?"] = "n",
h?"] = "m",
= "n",
= "m",
= "n",
}
-- translit any words or phrases
function export.tr(text, lang, sc)
local c = "(਼?)"
local y = "ਯ"
local v = "()"
local virama = "੍"
local n = "(?)"
local nukta = "(਼)"
local can_drop = mw.ustring.gsub(c,y,"")
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")
-- mw.log(text)
text = mw.ustring.gsub(text,v..n..can_drop.."a ","%1%2%3 ") --ending
-- mw.log(text)
text = mw.ustring.gsub(text,v..n..can_drop.."a"..c..v,"%1%2%3%4%5")
-- mw.log(text)
text = mw.ustring.gsub(text,nukta,conv)
text = mw.ustring.gsub(text,".",conv)
for key,val in pairs(nasal_assim) do
text = mw.ustring.gsub(text,"N("..key..")",val.."%1")
end
text = mw.ustring.gsub(text,"()N ", "%1̃ ")
text = mw.ustring.gsub(text,"(.?)N", "%1̃")
text = mw.ustring.gsub(text,"ː(.)","%1%1")
text = mw.ustring.gsub(text," ?।",".")
text = mw.ustring.gsub(text," $","")
return mw.ustring.toNFC(text)
end
return export