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