Modul:Babel/data/check
Penampilan
< Modul:Babel | data
- Berikut merupakan pendokumenan yang terletak di Modul:Babel/data/check/doc. [sunting] Kategori dijana secara automatik oleh Modul:pendokumenan. [sunting]
- Pautan berguna: akar laman • sublaman akar laman • pautan • transklusi • kes ujian • kotak pasir
- Number of warnings
- 2
| subpage | warnings |
|---|---|
| /data | UPA: invalid script code |
| /data | IPA: invalid script code |
local export = {}
--[=[
Prints out a wikitable with warnings for the following:
- All-uppercased language codes (as GEZ and TI were, before the switch to module)
- Whitespace in language codes (matches stuff like "User ojp" where there should be "ojp")
- Invalid language codes (also checks whether defined in custom_codes)
- Gender switches missing delimiter (like {masculine+feminine} instead of {masculine+feminine+})
- Messages missing proper markup: bolding, category links
]=]--
local m_data = mw.loadData("Module:Babel/data")
local get_by_code = require("Module:languages").getByCode
local sc_get_by_code = require("Module:scripts").getByCode
local char = string.char
local byte = string.byte
local sub = string.sub
local warnings = {}
local n = 1
local function ins(...)
warnings[n] = ...
n = n + 1
end
for code, glyph in pairs(m_data.script_glyphs) do
if not sc_get_by_code(code) then
ins({[2] = code .. ": invalid script code", is_root = true})
end
if glyph == "A" then
ins({[2] = glyph .. ": redundant " .. code .. " glyph", is_root = true})
end
end
for code, _ in pairs(m_data.custom_codes) do
if get_by_code(code, false, true) then
ins({[2] = code .. ": redundant custom code", is_root = true})
end
local has_message = false
local subpage = mw.loadData("Module:Babel/data/" .. sub(code, 1, 1))
for _, i in ipairs{"0", "1", "2", "3", "4", "5", "N"} do
if subpage[code .. "-" .. i] then
has_message = true
break
end
end
if not has_message then
ins({[2] = code .. ": custom code does not have any corresponding messages and should be removed", is_root = true})
end
end
for _, content in pairs(m_data.proglangs) do
if not content.link then
ins({[2] = code .. ": missing link", is_root = true})
end
end
local function get_subpage_warnings(letter)
for lang, message in pairs(mw.loadData("Module:Babel/data/" .. letter)) do
local lang_n = lang
local proficiency = lang:match("[012345N]$")
lang = lang:gsub("-[012345N]$", "")
local truncated = lang:gsub("-[012345N]$", ""):gsub("-%u%l%l%l", "")
if not get_by_code(truncated, false, true) and not m_data.custom_codes[truncated] then
if mw.language.isKnownLanguageTag(lang:lower()) then
ins({lang, lang .. ": wikimedia language code not in WT:LOL"})
else
ins({lang, lang .. ": invalid language code"})
end
end
if truncated:find("^[A-Z%-]+$") then
ins({lang, lang .. ": uppercase language code"})
end
if truncated:find("%s") then
ins({lang, lang .. ": space in language code"})
end
if message:find("{[^}]+}") and not message:find("%+[^+]+%+[^}]*}") then
ins({lang, lang_n .. ": gender switch missing second delimiter"})
end
if proficiency ~= "0" and not message:find("%[%[$1|[^]]+%]%]") then
ins({lang, lang_n .. ": missing $1 cat link"})
elseif proficiency == "0" and message:find("%[%[$1|[^]]+%]%]") then
ins({lang, lang_n .. ": has extraneous $1 cat link"})
end
if not message:find("%[%[$2|[^]]+%]%]") then
ins({lang, lang_n .. ": missing $2 cat link"})
end
if not message:find("'''") or message:find("%w%[%[$[12]|[^]]+%]%]%w") then
ins({lang, lang_n .. ": missing bolding"})
end
if message:find("''' ?'''") then
ins({lang, lang_n .. ": has adjacent bold tags"})
end
if message:find("$3") then
ins({lang, lang_n .. ": missing lang name"})
end
if message:lower():find(":cat")then
ins({lang, lang_n .. ": has raw category link"})
end
end
end
local letter = "a"
local warnings_hash, warnings_res = {}, {}
for i = 1, 26 do
get_subpage_warnings(letter)
letter = char(byte(letter) + 1)
end
for n, i in ipairs(warnings) do
-- remove duplicates from table
if not warnings_hash[i[2]] then
warnings_res[n] = i
warnings_hash[i[2]] = true
end
end
function export.show()
local purge = '<span style="color: var(--wikt-palette-indigo-9,#0022BB);' ..
'border:1px solid var(--border-color-base,#AAAAAA);' ..
'background-color:var(--wikt-palette-paleblue,#F9F9F9);' ..
'padding-left: 10px;padding-right:10px;font-size:90%;' ..
'text-weight: none; text-decoration: none;font-style:normal;">' ..
'[[Special:ApiSandbox#action=purge&format=json&generator=prefixsearch' ..
'&formatversion=2&gpssearch=Module%3ABabel%2Fdata|Purge all data pages]]' ..
'</span>'
if not warnings[1] then return ";Number of warnings: 0\n" .. purge end
wikitable = '{| class="wikitable"\n!subpage\n!warnings\n|-\n'
for _, i in ipairs(warnings_res) do
local subpage = "/data"
if not i.is_root then subpage = subpage .. "/" .. sub(i[1], 1, 1) end
wikitable = wikitable .. "|[[Module:Babel" .. subpage .. "|" .. subpage .. "]]\n|" .. i[2] .. "\n|-\n"
end
return ";Number of warnings:" .. #warnings_res .. "\n" .. purge .. "\n" .. wikitable .. "|}"
end
return export