local p = {}
function p.main(frame)
local word = mw.text.trim(frame.args or '')
if word == '' then return end
-- Normalize to composed form (NFC) for consistent processing
word = mw.ustring.toNFC(word)
-- Define Gurmukhi combining characters (vowel signs, diacritics)
local combining = {
= true, -- Nukta (਼)
= true, -- Vowel sign aa (ਾ)
= true, -- Vowel sign i (ਿ)
= true, -- Vowel sign ii (ੀ)
= true, -- Vowel sign u (ੁ)
= true, -- Vowel sign uu (ੂ)
= true, -- Vowel sign ee (ੇ)
= true, -- Vowel sign ai (ੈ)
= true, -- Vowel sign oo (ੋ)
= true, -- Vowel sign au (ੌ)
= true, -- Virama (੍)
= true, -- Adak bindi (ਁ)
= true, -- Bindi (ਂ)
= true, -- Visarga (ਃ)
= true, -- Tippi (ੰ)
= true, -- Addak (ੱ)
}
-- Split into syllables using character positions
local syllables = {}
local current = ''
local len = mw.ustring.len(word)
for i = 1, len do
local char = mw.ustring.sub(word, i, i)
local cp = mw.ustring.codepoint(char)
if combining then
current = current .. char
else
if current ~= '' then
table.insert(syllables, current)
end
current = char
end
end
if current ~= '' then
table.insert(syllables, current)
end
-- Generate {{hyph|pa|...}} structure
local parts = table.concat(syllables, '|')
return mw.getCurrentFrame():expandTemplate{
title = 'hyph',
args = { 'pa', parts }
}
end
return p