Module:Case: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 4: | Line 4: | ||
function p.title_case(frame) | function p.title_case(frame) | ||
plain = false | |||
if frame.args.plain == "true" then | |||
plain = true | |||
end | |||
split = frame.args.split | split = frame.args.split | ||
if frame.args.split == "space" then | if frame.args.split == "space" then | ||
Line 13: | Line 13: | ||
end | end | ||
replace = split | replace = split | ||
if frame.args.replace ~= nil then | if frame.args.replace ~= "nil" then | ||
replace = frame.args.replace | replace = frame.args.replace | ||
end | end | ||
parts = mw.text.split(frame.args.link, split, | parts = mw.text.split(frame.args.link, split, plain) | ||
title = "" | title = "" | ||
for _, part in pairs(parts) do | for _, part in pairs(parts) do |
Revision as of 22:52, 22 May 2021
See usage on Template, Template:u, and template:l.
local p = {} --p stands for package
langObject = mw.getLanguage('simple')
function p.title_case(frame)
plain = false
if frame.args.plain == "true" then
plain = true
end
split = frame.args.split
if frame.args.split == "space" then
split = " "
end
replace = split
if frame.args.replace ~= "nil" then
replace = frame.args.replace
end
parts = mw.text.split(frame.args.link, split, plain)
title = ""
for _, part in pairs(parts) do
title = title .. langObject:ucfirst(string.lower(part)) .. replace
end
if table.getn(parts) > 1 then
title = string.sub(title, 0, string.len(title) - 1)
end
return "[[" .. frame.args.link .. "|" .. title .. "]]"
end
function p.uppercase_first_letter(frame)
return "[[" .. frame.args.link .. "|" .. langObject:ucfirst(string.lower(frame.args.link)) .. "]]"
end
function p.lowercase(frame)
return "[[" .. frame.args.link .. "|" .. string.lower(frame.args.link) .. "]]"
end
return p