Модуль:Песочница/Pok: различия между версиями

мНет описания правки
Нет описания правки
 
(не показано 89 промежуточных версий этого же участника)
Строка 1: Строка 1:
local p = {}
local p = {}
local getArgs = require('Module:Arguments').getArgs


local rules = {
function p.main(frame)
     {"ие$", "ие", "ия"},  -- здание -> здания
    local args = getArgs(frame, { removeBlanks = false })
     {"ка$", "ка", "ки"},  -- собака -> собаки
     local name = args[1] or ""
     {"ок$", "ок", "ки"},  -- носок -> носки
     local attributes = args[2] or ""
    {"ец$", "ец", "цы"},  -- столбец -> столбцы
     if name == "" then
    {"ье$", "ье", "ья"},  -- зелье -> зелья
        return "<span class=\"error\">Ошибка: не указано имя файла.</span>"
    {"е$", "е", "я"},    -- поле -> поля
     end
     {"й$", "й", "и"},    -- край -> края
     local ext = (args["ext"] or "png"):gsub("^%.", "")
     {"ь$", "ь", "и"},    -- лошадь -> лошади
     local namespace = args["namespace"] or "Файл"
    {"о$", "о", "а"},    -- окно -> окна
     local max = tonumber(args["max"]) or 50
     {"ый$", "ый", "ые"},  -- малый -> малые, новый -> новые
     local include_base = (args["base"] ~= "no")
     {"ий$", "ий", "ие"},  -- синий -> синие
 
     {"ой$", "ой", "ие"},  -- большой -> большие
     local found = {}
    {"ое$", "ое", "ые"},  -- холодное -> холодные
     {"ее$", "ее", "ие"}  -- синее -> синие
}


function p.main(frame)
    if include_base then
    local text = frame.args[1] or ""
        local t = mw.title.new("Файл:" .. name .. "." .. ext)
    local words = {}
         if t and t.exists then
    for word in text:gmatch("%S+") do
             table.insert(found, "")
        -- Если слово заканчивается на "о" или "я", оставляем без изменений
         end
         if word:match("[оя]$") then
    end
             table.insert(words, word)
 
         else
    for i = 1, max do
            local pluralized = nil
        local t = mw.title.new("Файл:" .. name .. "-" .. i .. "." .. ext)
            for _, rule in ipairs(rules) do
        if t and t.exists then
                if word:match(rule[1]) then
             table.insert(found, "-" .. i)
                    pluralized = word:gsub(rule[2].."$", rule[3])
                    break
                end
            end
            if not pluralized then
                pluralized = word .. "ы"
            end
             table.insert(words, pluralized)
         end
         end
     end
     end
     return table.concat(words, " ")
 
     if #found == 0 then
        return ""
    end
 
    local before = "[[" .. namespace .. ":" .. name
    local after = "." .. ext .. "|" .. attributes .. "]]"
 
    local parts = {}
    table.insert(parts, "<choose before=\"" .. before .. "\" after=\"" .. after .. "\">")
    for _, suf in ipairs(found) do
        table.insert(parts, "<option>" .. suf .. "</option>")
    end
    table.insert(parts, "</choose>")
 
    return frame:preprocess(table.concat(parts, "\n"))
end
end


return p
return p