Module:Case: Difference between revisions

From Heroes 3 wiki
Jump to navigation Jump to search
No edit summary
(that line did nothing)
 
(24 intermediate revisions by the same user not shown)
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 langObject:lc(value) == langObject:lc(val) then
            return true
        end
    end
    return false
end


function p.title_case(frame)
function p.title_case(frame)
plain = true
plain = false
if frame.args.plain == "false" then
if frame.args.plain == "true" then
plain = false
plain = true
end
end
split = frame.args.split
split = frame.args.split
if frame.args.split == "space" then
if split == "space" then
split = " "
split = " "
else
split = frame.args.split
end
end
replace = split
replace = split
if frame.args.replace == false then
if frame.args.replace ~= "" then
replace = frame.args.replace
replace = frame.args.replace
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 i, part in pairs(parts) do
  title = title .. langObject:ucfirst(string.lower(part)) .. replace
if i > 1 and i < table.getn(parts) and has_value(lower, part) then
title = title .. langObject:lc(part) .. replace
else
title = title .. langObject:ucfirst(langObject:lc(part)) .. replace
end
end
end
if table.getn(parts) > 1 then
if table.getn(parts) > 1 then
title = string.sub(title, 0, string.len(title) - 1)
title = string.sub(title, 0, string.len(title) - string.len(replace))
end
if frame.args.nolink == "true" then
return title
end
end
     return "[[" .. frame.args.link .. "|" .. title .. "]]"
     return "[[" .. frame.args.link .. "|" .. title .. "]]"
Line 30: Line 45:


function p.uppercase_first_letter(frame)
function p.uppercase_first_letter(frame)
     return "[[" .. frame.args.link .. "|" .. langObject:ucfirst(string.lower(frame.args.link)) .. "]]"
uc_first_letter = langObject:ucfirst(langObject:lc(frame.args.link))
if frame.args.nolink == "true" then
return uc_first_letter
end
     return "[[" .. frame.args.link .. "|" .. uc_first_letter .. "]]"
end
end


function p.lowercase(frame)
function p.lowercase(frame)
     return "[[" .. frame.args.link .. "|" .. string.lower(frame.args.link) .. "]]"
lc = langObject:lc(frame.args.link)
if frame.args.nolink == "true" then
return lc
end
     return "[[" .. frame.args.link .. "|" .. lc .. "]]"
end
end


return p
return p

Latest revision as of 06: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 langObject:lc(value) == langObject:lc(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 i, part in pairs(parts) do
		if i > 1 and i < table.getn(parts) and 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
	if frame.args.nolink == "true" then
		return title
	end
    return "[[" .. frame.args.link .. "|" .. title .. "]]"
end

function p.uppercase_first_letter(frame)
	uc_first_letter = langObject:ucfirst(langObject:lc(frame.args.link))
	if frame.args.nolink == "true" then
		return uc_first_letter
	end
    return "[[" .. frame.args.link .. "|" .. uc_first_letter .. "]]"
end

function p.lowercase(frame)
	lc = langObject:lc(frame.args.link)
	if frame.args.nolink == "true" then
		return lc
	end
    return "[[" .. frame.args.link .. "|" .. lc .. "]]"
end

return p