10,731
edits
TheNightAvl (talk | contribs) No edit summary Tag: Reverted |
TheNightAvl (talk | contribs) (I DID IT!!! (Made %p for part of speech functional)) Tag: Reverted |
||
Line 54: | Line 54: | ||
-- Expands a pattern containing %l (and optionally %u), adding versions | -- Expands a pattern containing %l (and optionally %u), adding versions | ||
-- of the pattern for each possible language | -- of the pattern for each possible language | ||
local function hydrate_pattern_l(out_patterns, p_lua, p_categories, also_u) | local function hydrate_pattern_l(out_patterns, p_lua, p_categories, also_u, also_p) | ||
for _, l_data in pairs(d_languages) do | for _, l_data in pairs(d_languages) do | ||
if also_p then | |||
for _, pos in ipairs(d_pos) do | |||
if also_u then | |||
for _, l2_data in pairs(d_languages) do | |||
if l2_data.code ~= l_data.code then | |||
local p_out_cats = {} | |||
for _, p_cat in ipairs(p_categories) do | |||
table.insert(p_out_cats, replace(p_cat, {["%%l"] = l_data.name, ["%%u"] = l2_data.name, ["^%%p"] = capitalize(pos), ["%%p"] = pos})) | |||
end | |||
table.insert(out_patterns, to_pattern(replace(p_lua, {["%%l"] = sanitize(l_data.name), ["%%u"] = sanitize(l2_data.name), ["^%%p"] = capitalize(pos), ["%%p"] = pos}), p_out_cats)) | |||
end | |||
end | |||
else | |||
local p_out_cats = {} | |||
for _, p_cat in ipairs(p_categories) do | |||
table.insert(p_out_cats, replace(p_cat, {["%%l"] = l_data.name, ["^%%p"] = capitalize(pos), ["%%p"] = pos})) | |||
end | |||
table.insert(out_patterns, to_pattern(replace(p_lua, {["%%l"] = sanitize(l_data.name), ["^%%p"] = capitalize(pos), ["%%p"] = pos}), p_out_cats)) | |||
end | |||
end | |||
else | |||
if also_u then | |||
for _, l2_data in pairs(d_languages) do | |||
if l2_data.code ~= l_data.code then | |||
local p_out_cats = {} | |||
for _, p_cat in ipairs(p_categories) do | |||
table.insert(p_out_cats, replace(p_cat, {["%%l"] = l_data.name, ["%%u"] = l2_data.name})) | |||
end | |||
table.insert(out_patterns, to_pattern(replace(p_lua, {["%%l"] = sanitize(l_data.name), ["%%u"] = sanitize(l2_data.name)}), p_out_cats)) | |||
end | |||
end | |||
else | |||
local p_out_cats = {} | |||
for _, p_cat in ipairs(p_categories) do | |||
table.insert(p_out_cats, replace(p_cat, {["%%l"] = l_data.name})) | |||
end | |||
table.insert(out_patterns, to_pattern(replace(p_lua, {["%%l"] = sanitize(l_data.name)}), p_out_cats)) | |||
end | |||
end | end | ||
end | end | ||
Line 87: | Line 109: | ||
local function hydrate_pattern_p(out_patterns, p_lua, p_categories) | local function hydrate_pattern_p(out_patterns, p_lua, p_categories) | ||
for _, | 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( | table.insert(p_out_cats, replace(p_cat, {["^%%p"] = capitalize(pos), ["%%p"] = pos})) | ||
end | end | ||
table.insert(out_patterns, to_pattern(replace(p_lua, {["^%%p"] = capitalize( | table.insert(out_patterns, to_pattern(replace(p_lua, {["^%%p"] = capitalize(pos), ["%%p"] = pos}), p_out_cats)) | ||
end | end | ||
end | end | ||
Line 102: | Line 124: | ||
local p_lua = replace(sanitize(p_template), {["%%s"] = "(..-)"}) | local p_lua = replace(sanitize(p_template), {["%%s"] = "(..-)"}) | ||
if mw.ustring.find(p_template, "%%l") ~= nil then | if mw.ustring.find(p_template, "%%l") ~= nil then | ||
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, mw.ustring.find(p_template, "%%p") ~= 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) | hydrate_pattern_c(out_patterns, p_lua, p_categories) |