Модуль:Песочница/Pok: различия между версиями
Материал из Space Station 14 Вики
Pok (обсуждение | вклад) м Полностью удалено содержимое страницы Метки: очистка ручная отмена |
Pok (обсуждение | вклад) мНет описания правки Метка: отменено |
||
| Строка 1: | Строка 1: | ||
-- Загрузка данных | |||
local accentData = mw.loadData("Модуль:IanComradeBot/prototypes/accent.json/data") | |||
local p = {} | |||
function p.table(frame) | |||
local targetId = frame.args[1] or "" | |||
if targetId == "" then | |||
return "Ошибка: не указан параметр id." | |||
end | |||
local foundData = nil | |||
for _, item in ipairs(accentData) do | |||
if item.id == targetId then | |||
foundData = item | |||
break | |||
end | |||
end | |||
if not foundData then | |||
return "Ошибка: данные по id '" .. targetId .. "' не найдены." | |||
end | |||
local output = {} | |||
table.insert(output, '{| class="sortable-grid sortable-grid--small-column sortable"') | |||
table.insert(output, '! Сортировка (по алфавиту)') | |||
table.insert(output, '|-') | |||
for key, value in pairs(foundData.wordReplacements) do | |||
local keyData = "{{#invoke:Ftl|main|translation|".. key .."}}" | |||
local valueData = "{{#invoke:Ftl|main|translation|".. value .."}}" | |||
if keyData ~= "Ошибка: Ключ не найден." and valueData ~= "Ошибка: Ключ не найден." then | |||
table.insert(output, "|") | |||
table.insert( | |||
output, | |||
frame:preprocess( | |||
string.format( | |||
"{{Cut-Layout|arrow=1|background-color=var(--bg-color-message-subtle)|%s|%s}}", | |||
keyData, | |||
valueData | |||
) | |||
) | |||
) | |||
table.insert(output, "|-") | |||
end | |||
end | |||
table.insert(output, '|}') | |||
return table.concat(output, "\n") | |||
end | |||
return p | |||
Версия от 22:52, 15 апреля 2025
Для документации этого модуля может быть создана страница Модуль:Песочница/Pok/doc
-- Загрузка данных
local accentData = mw.loadData("Модуль:IanComradeBot/prototypes/accent.json/data")
local p = {}
function p.table(frame)
local targetId = frame.args[1] or ""
if targetId == "" then
return "Ошибка: не указан параметр id."
end
local foundData = nil
for _, item in ipairs(accentData) do
if item.id == targetId then
foundData = item
break
end
end
if not foundData then
return "Ошибка: данные по id '" .. targetId .. "' не найдены."
end
local output = {}
table.insert(output, '{| class="sortable-grid sortable-grid--small-column sortable"')
table.insert(output, '! Сортировка (по алфавиту)')
table.insert(output, '|-')
for key, value in pairs(foundData.wordReplacements) do
local keyData = "{{#invoke:Ftl|main|translation|".. key .."}}"
local valueData = "{{#invoke:Ftl|main|translation|".. value .."}}"
if keyData ~= "Ошибка: Ключ не найден." and valueData ~= "Ошибка: Ключ не найден." then
table.insert(output, "|")
table.insert(
output,
frame:preprocess(
string.format(
"{{Cut-Layout|arrow=1|background-color=var(--bg-color-message-subtle)|%s|%s}}",
keyData,
valueData
)
)
)
table.insert(output, "|-")
end
end
table.insert(output, '|}')
return table.concat(output, "\n")
end
return p