Module:accent qualifier
Ang dokumentasyon ng ng modyul na ito ay maaaring likhain sa Module:accent qualifier/doc
local export = {}
local m_qualifier = require("Module:qualifier")
function export.show(frame)
data = mw.loadData("Module:accent qualifier/data")
local args = frame.getParent and frame:getParent().args or frame
if (not args[1] or args[1] == "") and mw.title.getCurrentTitle().nsText == "Template" then
return m_qualifier.format_qualifier({'{{{1}}}'})
end
local params = {
[1] = {required = true, list = true}
}
local inputs = require("Module:parameters").process(args, params)
local accents = {}
for _, accent in ipairs(inputs[1]) do
if data[accent] then
if data[accent].link then
table.insert(accents, "[[w:" .. data[accent].link .. "|" ..
(data[accent].display or data[accent].link) .. "]]")
elseif data[accent].display then
table.insert(accents, data[accent].display)
end
else
table.insert(accents, accent)
end
end
return m_qualifier.format_qualifier(accents)
end
function export.checkusage()
if mw.title.getCurrentTitle().nsText ~= "" then
return ""
end
local content = mw.title.getCurrentTitle():getContent()
local length = mw.ustring.len(content)
local iterate_find = function(pattern)
local index = 1
return function()
index = mw.ustring.find(content, pattern, index+5)
return index
end
end
local indices = {}
for index in iterate_find("===+ *Pronunciation *===+") do
local next_hyphens = mw.ustring.find(content, "\n%-%-%-%-", index) or length
local next_equals = mw.ustring.find(content, "\n==+[^\n]+==+", index) or length
table.insert(indices, {index, math.min(next_hyphens, next_equals)})
end
for index in iterate_find("{{a|") do
local valid = false
for _,locations in ipairs(indices) do
if locations[1] < index and index < locations[2] then
valid = true
end
end
if not valid then
return "[[Category:usage of a in wrong position]]"
end
end
return ""
end
return export