Difference between revisions of "Module:CapitalizationCheck"
From Nookipedia, the Animal Crossing wiki
PanchamBro (talk | contribs) m |
PanchamBro (talk | contribs) (adding New Leaf to capitalization check module) |
||
(17 intermediate revisions by the same user not shown) | |||
Line 29: | Line 29: | ||
return false | return false | ||
end | end | ||
+ | end | ||
+ | |||
+ | function isEmpty(s) | ||
+ | return s == nil or s == '' | ||
end | end | ||
function p.main(frame) | function p.main(frame) | ||
+ | local print = '' | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
local compare = args[1] or '' | local compare = args[1] or '' | ||
local game = args[2] or '' | local game = args[2] or '' | ||
− | + | if checkCaps(compare, game) == false then | |
+ | print = "[[Category:Pages with item names improperly capitalized]]" | ||
+ | end | ||
+ | return print | ||
end | end | ||
Line 43: | Line 51: | ||
end | end | ||
− | function | + | function checkCaps(compare, game) |
− | |||
local sentenceCase = "" | local sentenceCase = "" | ||
− | if checkFirstGen(game) then | + | if checkFirstGen(game) and not isEmpty(data.firstGen[compare:lower()]) then |
if compare == firstToUpper(data.firstGen[compare:lower()]) then | if compare == firstToUpper(data.firstGen[compare:lower()]) then | ||
− | return | + | return true |
− | elseif compare | + | elseif compare == data.firstGen[compare:lower()] then |
− | return | + | return true |
else | else | ||
− | + | return false | |
− | return | ||
end | end | ||
− | elseif game == "WW" or game == "Wild World" then | + | elseif (game == "WW" or game == "Wild World") and not isEmpty(data.wildWorld[compare:lower()]) then |
if compare == firstToUpper(data.wildWorld[compare:lower()]) then | if compare == firstToUpper(data.wildWorld[compare:lower()]) then | ||
− | return | + | return true |
− | elseif compare | + | elseif compare == data.wildWorld[compare:lower()] then |
− | return | + | return true |
+ | else | ||
+ | return false | ||
+ | end | ||
+ | elseif (game == "NL" or game == "New Leaf") and not isEmpty(data.newLeaf[compare:lower()]) then | ||
+ | if compare == firstToUpper(data.newLeaf[compare:lower()]) then | ||
+ | return true | ||
+ | elseif compare == data.newLeaf[compare:lower()] then | ||
+ | return true | ||
else | else | ||
− | + | return false | |
− | return | ||
end | end | ||
− | elseif game == "NH" or game == "New Horizons" | + | elseif (game == "NH" or game == "New Horizons") and not isEmpty(data.newHorizons[compare:lower()]) then |
− | |||
− | |||
if compare == firstToUpper(data.newHorizons[compare:lower()]) then | if compare == firstToUpper(data.newHorizons[compare:lower()]) then | ||
− | return | + | return true |
− | elseif compare | + | elseif compare == data.newHorizons[compare:lower()] then |
− | return | + | return true |
else | else | ||
− | + | return false | |
− | return | ||
end | end | ||
+ | else | ||
+ | return false | ||
end | end | ||
end | end | ||
return p | return p |
Latest revision as of 00:48, December 3, 2022
Documentation for this module may be created at Module:CapitalizationCheck/doc
local p = {}
local getArgs = require('Module:Arguments').getArgs
data = mw.loadData("Module:CapitalizationCheck/Data")
function checkFirstGen(s)
if s == "DnM" then
return true
elseif s == "Doubutsu no Mori" then
return true
elseif s == "DnM+" then
return true
elseif s == "Doubutsu no Mori+" then
return true
elseif s == "PG" then
return true
elseif s == "Animal Crossing" then
return true
elseif s == "DnMe+" then
return true
elseif s == "Doubutsu no Mori e+" then
return true
elseif s == "iQue" then
return true
elseif s == "Dòngwù Sēnlín" then
return true
elseif s == "Dongwu Senlin" then
return true
else
return false
end
end
function isEmpty(s)
return s == nil or s == ''
end
function p.main(frame)
local print = ''
local args = getArgs(frame)
local compare = args[1] or ''
local game = args[2] or ''
if checkCaps(compare, game) == false then
print = "[[Category:Pages with item names improperly capitalized]]"
end
return print
end
-- https://stackoverflow.com/questions/2421695/first-character-uppercase-lua
function firstToUpper(str)
return (str:gsub("^%l", string.upper))
end
function checkCaps(compare, game)
local sentenceCase = ""
if checkFirstGen(game) and not isEmpty(data.firstGen[compare:lower()]) then
if compare == firstToUpper(data.firstGen[compare:lower()]) then
return true
elseif compare == data.firstGen[compare:lower()] then
return true
else
return false
end
elseif (game == "WW" or game == "Wild World") and not isEmpty(data.wildWorld[compare:lower()]) then
if compare == firstToUpper(data.wildWorld[compare:lower()]) then
return true
elseif compare == data.wildWorld[compare:lower()] then
return true
else
return false
end
elseif (game == "NL" or game == "New Leaf") and not isEmpty(data.newLeaf[compare:lower()]) then
if compare == firstToUpper(data.newLeaf[compare:lower()]) then
return true
elseif compare == data.newLeaf[compare:lower()] then
return true
else
return false
end
elseif (game == "NH" or game == "New Horizons") and not isEmpty(data.newHorizons[compare:lower()]) then
if compare == firstToUpper(data.newHorizons[compare:lower()]) then
return true
elseif compare == data.newHorizons[compare:lower()] then
return true
else
return false
end
else
return false
end
end
return p