Ad placeholder

Module:ParseList: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
Line 50: Line 50:
}
}


local function pluralize(str)
local function makePlural(str)
local sp = specialPlurals[str]
local sp = specialPlurals[str]
if sp then
if sp then
Line 59: Line 59:
end
end
return str .. "s"
return str .. "s"
end
local function makeSingular(str)
local special
for k, v in pairs(specialPlurals) do
if v == str then
special = k
break
end
end
if special then
return special
end
if str:sub(-3) == "ies" then
return str:sub(1, -4) .. "y"
end
return str:sub(1, -2)
end
end


local function processElement(str)
local function processElement(str)
local modified = str
if makeElementsPlural then
if makeElementsPlural then
local plural = pluralize(str)
modified = makePlural(str)
if makeElementsLinks then
elseif makeElementsSingular then
return "[[" .. str .. "|" .. plural .. "]]"
modified = makeSingular(str)
else
end
return plural
if makeElementsLinks then
end
return "[[" .. str .. "|" .. modified .. "]]"
else
else
if makeElementsLinks then
return modified
return "[[" .. str .. "]]"
else
return str
end
end
end
end
end
Line 128: Line 142:
listDelimiters = args['delimiter'] or ","
listDelimiters = args['delimiter'] or ","
makeElementsLinks = args['makeLinks']
makeElementsLinks = args['makeLinks']
makeElementsPlural = args['pluralize'] or args['makePlural']
makeElementsPlural = args['makePlural']
makeElementsSingular = args['makeSingular']
makeElementsSingular = args['makeSingular']
finalJoiningWord = args['joinWord'] or args['joiningWord'] or "and"
finalJoiningWord = args['joinWord'] or "and"
local type = args['type'] or 'sentence'
local type = args['type'] or 'sentence'

Navigation menu