Modul:wanted entries
A modult a Modul:wanted entries/doc lapon tudod dokumentálni
local export = {}
local language_specific_regexes = {
["he"] = {"{{l/he%|.-}}"},
["ja"] = {"{{ja%-l%|.-}}"},
}
local we_list = mw.loadData("Module:wanted entries/data").we_list
-- Generates a full subpage like WT:Wanted_entries/pt.
function export.subpage (frame)
-- The language_code contains the language code which is the subpage ("pt" in "Wiktionary:Wanted entries/pt").
local page_title = mw.title.getCurrentTitle()
local language_code = page_title.subpageText
-- If the language_code contains a dash (like ine-pro), it is replaced by %%- here, which in turn becomes %- in the variable, which is parsed as a simple - below.
language_code = string.gsub (language_code, "-", "%%-")
local link_template_pattern = "{{l%|" .. language_code .. "%|.-}}"
-- This locates the links that use the specific language code in the unparsed list, then parses the list contaning only with entries of the specific language.
local language_list = ""
for line in string.gmatch (we_list, "[^\n]+") do
local match = false
if string.match (line, link_template_pattern) then
match = true
elseif language_specific_regexes[language_code] then
for _, regex in ipairs (language_specific_regexes[language_code]) do
if string.match (line, regex) then
match = true
break
end
end
end
if match then
language_list = language_list .. line .. "\n"
end
end
language_list = frame:preprocess(language_list)
-- Gets multiple parts of the page from separate pages.
local top = frame:expandTemplate {title = "Template:wanted entries subpage/top"}
local bottom = frame:expandTemplate {title = "Template:wanted entries subpage/bottom"}
local categories = frame:expandTemplate {title = "Template:wanted entries subpage/categories"}
-- Tests if the language_list is empty. If so, generates an error message.
if language_list == "" then
language_list = "''There are no wanted entries in this language.''"
end
-- Merges different variables to form the end result.
local result = top .. "\n" .. language_list .. bottom .. categories
return result
end
-- Counts how many wanted entries of a given language are there in WT:Wanted_entries.
function export.language_count (frame)
local args = frame.args
-- The language_code comes from the argument lang= passed to the module.
local language_code = args.lang
-- If the language_code contains a dash (like ine-pro), it is replaced by %%- here, which in turn becomes %- in the variable, which is parsed as a simple - below.
language_code = string.gsub (language_code, "-", "%%-")
-- The count starts at 0 and is incremented for each wanted entry in the given language.
local language_count = 0
local _, count = string.gsub (we_list, "{{l%|" .. language_code .. "%|.-}}", "")
language_count = language_count + count
if language_specific_regexes[language_code] then
for _, regex in ipairs (language_specific_regexes[language_code] or {}) do
local _, count = string.gsub (we_list, regex, "")
language_count = language_count + count
end
end
-- Returns the number.
return language_count
end
return export