Модуль:Тільки для

Матеріал з Minecraft Wiki
Перейти до: навігація, пошук
[створити | історія | оновити]Документація
У цього модуля немає документації. Якщо ви знаєте, як використовувати цей модуль, будь ласка, додайте відповідну інформацію.
local p = {}

-- Приведення назв видань до нормалізованих
local edition_names = {
	["комп'ютер"] = "java",
	["пк"] = "java",
	["java"] = "java",
	["Java"] = "java",
	
	["pocket"] = "bedrock",
	["Pocket"] = "bedrock",
	["bedrock"] = "bedrock",
	["Bedrock"] = "bedrock",
	
	["console"] = "console",
	["Console"] = "console",
	["legacy console"] = "console",
	["Legacy console"] = "console",
	
	["PlayStation 4"] = "ps4",
	["ps4"] = "ps4",
	
	["education"] = "education",
	["Education"] = "education",
	
	["new3ds"] = "3ds",
	["New3ds"] = "3ds",
	["nintendo"] = "3ds",
	["Nintendo"] = "3ds",
	["new nintendo 3ds"] = "3ds",
	["New Nintendo 3DS"] = "3ds",
	
	["earth"] = "minecraft earth",
	["Minecraft earth"] = "minecraft earth",
	["Minecraft Earth"] = "minecraft earth",
	["Earth"] = "minecraft earth",
}

-- Дані про видання
local editions = {
	["java"] = {link = "Java Edition", title = "Java Edition", category = "Java Edition"},
	["bedrock"] = {link = "Bedrock Edition", title = "Bedrock Edition", category = "Bedrock Edition"},
	["console"] = {link = "Legacy Console Edition", title = "Legacy Console Edition", category = "Legacy Console Edition"},
	["ps4"] = {link = "PlayStation 4 Edition", title = "PlayStation 4 Edition", category = "PlayStation 4 Edition"},
	["education"] = {link = "Education Edition", title = "Education Edition", category = "Education Edition"},
	["3ds"] = {link = "New Nintendo 3DS Edition", title = "New Nintendo 3DS Edition", category = "New Nintendo 3DS Edition"},
	["minecraft earth"] = {link = "Minecraft Earth", title = "Minecraft Earth", category = "Minecraft Earth"}
}

function p.only(f)
	local args = f.args or f
	if f == mw.getCurrentFrame() and args[1] == nil then
		args = f:getParent().args
	end
	
	local params = {}
	local edition_text = {}
	local categories = {}
	local lang = mw.language.getContentLanguage()
	
	for i, v in ipairs(args) do
		local edition_name = mw.text.trim(v)
		if edition_names[edition_name] then
			local edition = editions[edition_names[edition_name]]
			table.insert(edition_text, ("[[%s|%s]]"):format(edition.link, edition.title))
			table.insert(categories, ("[[Категорія:%s]]"):format(edition.category))
		else
			local link = lang:ucfirst(edition_name) .. " Edition"
			table.insert(edition_text, ("[[%s]]"):format(link))
			table.insert(categories, ("[[Категорія:%s]]"):format(edition_name))
		end
	end
	
	local text = "'''Тільки для "
	local n_editions = #edition_text
	for i, link in ipairs(edition_text) do
		if i > 1 then
			if i == n_editions then
				text = text .. " и "
			else
				text = text .. ", "
			end
		end
		text = text .. link
	end
	text = text .. "'''"
	
	--params["border"] = "blue"
	--params["зображення"] = "Information icon.svg"
	params["текст"] = text
	
	local result = mw.getCurrentFrame():expandTemplate({title = "Msgline", args = params})
	if not args["безкат"] then
		local title = mw.title.getCurrentTitle()
		-- namespace 2 — «Користувач»
		if title.namespace ~= 2 and not title.isTalkPage then
			result = result .. table.concat(categories)
		end
	end
	return result
end

return p