Difference between revisions of "Module:SentenceCase"
From Nookipedia, the Animal Crossing wiki
PanchamBro (talk | contribs) m |
HylianAngel (talk | contribs) (Áo dài was showing up as "áo dài" in the infobox.) |
||
(2 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local getArgs = require('Module:Arguments').getArgs | local getArgs = require('Module:Arguments').getArgs | ||
+ | |||
+ | function search(category, substrings) | ||
+ | for k,v in pairs(substrings) do | ||
+ | if string.find(category, v) then | ||
+ | return true | ||
+ | end | ||
+ | end | ||
+ | return false | ||
+ | end | ||
function p.main(frame) | function p.main(frame) | ||
Line 10: | Line 19: | ||
-- https://stackoverflow.com/questions/2421695/first-character-uppercase-lua | -- https://stackoverflow.com/questions/2421695/first-character-uppercase-lua | ||
function p.firstToUpper(name) | function p.firstToUpper(name) | ||
− | + | local keepLowercase = {"iQue", "iQue shirt", "iQueGBA", "amiibo shelf"} | |
+ | local aoDai = {"áo dài"} | ||
+ | if search(name, keepLowercase) == true then | ||
+ | return name | ||
+ | elseif search(name, aoDai) == true then | ||
+ | return "Áo dài" | ||
+ | else | ||
+ | return (name:gsub("^%l", string.upper)) | ||
+ | end | ||
end | end | ||
return p | return p |
Latest revision as of 00:05, March 7, 2023
Documentation for this module may be created at Module:SentenceCase/doc
local p = {}
local getArgs = require('Module:Arguments').getArgs
function search(category, substrings)
for k,v in pairs(substrings) do
if string.find(category, v) then
return true
end
end
return false
end
function p.main(frame)
local args = getArgs(frame)
local name = args['1'] or ''
return p.firstToUpper(name)
end
-- https://stackoverflow.com/questions/2421695/first-character-uppercase-lua
function p.firstToUpper(name)
local keepLowercase = {"iQue", "iQue shirt", "iQueGBA", "amiibo shelf"}
local aoDai = {"áo dài"}
if search(name, keepLowercase) == true then
return name
elseif search(name, aoDai) == true then
return "Áo dài"
else
return (name:gsub("^%l", string.upper))
end
end
return p