Module:TVChannelList: Difference between revisions
Content deleted Content added
PeaceDeadC (talk | contribs) No edit summary |
PeaceDeadC (talk | contribs) No edit summary |
||
Line 110:
-- Function to find and retrieve channel data from appropriate module
function getChannel(name)
local modulesToTry = {}
table.insert(modulesToTry, firstLetter)
-- Handle "The" prefix
local nameWithoutThe = name:lower():gsub("^the%s*", ""):gsub("%s*", "")
if nameWithoutThe ~= name:lower() then
if theFirstLetter ~= firstLetter then
table.insert(modulesToTry, theFirstLetter)
end
▲ table.insert(modulesToTry, name:sub(1, 1):upper())
for _, module in ipairs(modulesToTry) do
local success, channelModule = pcall(require, 'Module:TVChannelList/' .. module)
if success then
if type(channelModule
local matchedChannels = {}▼
local matchedChannels = {}
-- First try direct match or aliases
▲ if channelModule.redirects and channelModule.redirects[name:lower()] then
if channel.name:lower() == name:lower() or
▲ end
(channel.aliases and table.contains(channel.aliases, name:lower())) then▼
▲ (channel.aliases and table.contains(channel.aliases, name:lower())) then
-- If found
return nil, i18n.errors.duplicateChannels
elseif #matchedChannels == 1 then▼
return matchedChannels[1]▼
end▼
-- If no direct matches found, try redirects
if channelModule.redirects and channelModule.redirects[name:lower()] then
return getChannel(channelModule.redirects[name:lower()])
end
mw.log('Invalid module structure: Module:TVChannelList/' .. module)
▲ return nil, i18n.errors.duplicateChannels
▲ elseif #matchedChannels == 1 then
▲ return matchedChannels[1]
end
else
| |||