Module:auto cat: Difference between revisions

Jump to navigation Jump to search
ਕੋਈ ਸੋਧ ਸਾਰ ਨਹੀਂ
No edit summary
Tag: Reverted
No edit summary
Tag: Reverted
Line 23: Line 23:
-- and can handle multiple replacements at once.
-- and can handle multiple replacements at once.
local function replace(str, gsubs)
local function replace(str, gsubs)
    local res = str
     for from, to in pairs(gsubs) do
     for from, to in pairs(gsubs) do
     res = tostring(mw.ustring.gsub(res, from, to))
     str = tostring(mw.ustring.gsub(str, from, to))
     end
     end
     return res
     return str
end
end


Line 87: Line 86:
end
end


local function hydrate_pattern_pos(out_patterns, p_lua, p_categories)
local function hydrate_pattern_p(out_patterns, p_lua, p_categories)
for l_code, l_data in pairs(d_languages) do
    for _, p_pos in ipairs(d_pos) do
for _, pos in ipairs(d_pos) do
    local p_out_cats = {}
        local p_out_cats = {}
        for _, p_cat in ipairs(p_categories) do
        for _, p_cat in ipairs(p_categories) do
            table.insert(p_out_cats, replace(p_cat, {["^%%p"] = capitalize(p_pos), ["%%p"] = p_pos}))
            table.insert(p_out_cats, replace(p_cat, {["%%l"] = l_data.name, ["%%c"] = l_code, ["^%%pos"] = capitalize(pos), ["%%pos"] = pos}))
        end
        end
        table.insert(out_patterns, to_pattern(replace(p_lua, {["^%%p"] = capitalize(p_pos), ["%%p"] = p_pos}), p_out_cats))
        table.insert(out_patterns, to_pattern(replace(p_lua, {["^%%pos"] = capitalize(pos), ["%%pos"] = pos}), p_out_cats))
end
end
end
end
end
Line 107: Line 104:
             hydrate_pattern_l(out_patterns, p_lua, p_categories, mw.ustring.find(p_template, "%%u") ~= nil)
             hydrate_pattern_l(out_patterns, p_lua, p_categories, mw.ustring.find(p_template, "%%u") ~= nil)
         elseif mw.ustring.find(p_template, "%%c") ~= nil then
         elseif mw.ustring.find(p_template, "%%c") ~= nil then
            hydrate_pattern_c(out_patterns, p_lua, p_categories)
        elseif mw.ustring.find(p_template, "%%pos") ~= nil then
hydrate_pattern_c(out_patterns, p_lua, p_categories)
hydrate_pattern_c(out_patterns, p_lua, p_categories)
elseif mw.ustring.find(p_template, "%%p") ~= nil then
            hydrate_pattern_p(out_patterns, p_lua, p_categories)
         else
         else
             table.insert(out_patterns, to_pattern(p_lua, p_categories))
             table.insert(out_patterns, to_pattern(p_lua, p_categories))
         end
         end
     end
     end
    mw.logObject(out_patterns)
     return out_patterns
     return out_patterns
end
end

Navigation menu