Module:Guru-translit
Appearance
- පහත දැක්වෙන උපදෙස්, Module:Guru-translit/documentation හි පිහිටා ඇත. Module:Guru-translit/documentation]]. [සංස්කරණය]
- ප්රයෝජනවත් සබැඳි: උප පිටු ලැයිස්තුව • සබැඳි • transclusions • testcases • sandbox
This module will transliterate text in the Gurmukhi අක්ෂරක්රමය. 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.
Functions
tr(text, lang, sc)
- Transliterates a given piece of
text
written in the script specified by the codesc
, and language specified by the codelang
. - 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", ["ੜ"] = "ṛ",
--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 = {
["[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 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,"([aiueaiauoāīū])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