Module:frp-IPA/utilities

local m_main = require("Module:frp-IPA") local data_page = "Module:frp-IPA/data" local frp = require("Module:languages").getByCode("frp")

local export = {}

local function make_status(res) return res and ("failed ❌\n" .. res) or "passed ✔\n" end

local function check_dupe_key local src = mw.title.new(data_page):getContent local seen = {} for key in src:gmatch('%["[^"\n]+"%]') do		if seen[key] then			return "** Duplicated code: \n"		end		seen[key] = true	end	return false end

local function check_comma local data = mw.loadData(data_page) for _, locs in pairs(data) do		for key, _ in pairs(locs) do			if key:match(",") then return "** Comma found in code: \n" end end end return false end

local function check_double_redir local data = mw.loadData(data_page) for _, locs in pairs(data) do		for key, val in pairs(locs) do			if type(val) == "string" and type(locs[val]) == "string" then return "** Double redirect found:  &rarr;   &rarr;  \n" end end end return false end

-- check the validity of Module:frp-IPA/data function export.check_data(frame) local dupe_key = check_dupe_key local comma = check_comma local double_redir = check_double_redir local all_pass = (not dupe_key) and (not comma) and (not double_redir) local msg = "* Checking for duplicate codes: " .. make_status(dupe_key) .. "* Checking for commas in codes: " .. make_status(comma) .. "* Checking for double redirects: " .. make_status(double_redir) if all_pass then return ' ' .. ' All test passed! ✔ '			.. ' \n' .. msg .. '\n ' else return '== Checks ==\n' .. msg end end

-- generate a template for calling Template:frp-IPA function export.template(frame) local function span(text,class) return text --return ' '..text..' ' end local res = "" res = res .. ' '	res = res .. "  "	return res end

local function gather_locs(loc_data) -- first pass: gather all the aliases local aliases = {} for key, val in pairs(loc_data) do		if type(val) == "string" then aliases[val] = key end end -- second pass: gather name, wiki, aliases local res = {} for key, val in pairs(loc_data) do		if type(val) ~= "string" then local alias = aliases[key] alias = alias and " " or "" local wiki = (type(val) == "table") and val.wiki or key local sortkey = frp:makeSortKey(key) table.insert(res, {key, wiki, alias, sortkey}) end end table.sort(res, function(a,b) return a[4] < b[4] end) return res end

-- make a table for Module:frp-IPA/data function export.make_table(frame) local data = mw.loadData(data_page) local accents = mw.loadData("Module:labels/data/lang/frp") local res = {} local function ins(text) table.insert(res,text) end ins('{| style="width:650px"') ins("|+ Localities for Template:frp-IPA") ins("|-") for _,code in ipairs(m_main.codes) do ins('{| class="wikitable vsSwitcher" style="width:650px; margin:0px" data-toggle-category="' .. accents[code] .. '"') ins('! colspan=3 style="position:relative;" | ' .. accents[code] .. " (" .. code .. ")"			.. ' ')		ins("|- class=vsHide") ins('! style="width:300px" | Name') ins('! style="width:300px" | Wiki') ins('! style="width:50px" | Number') for _,loc in ipairs(gather_locs(data[code])) do			ins("|- class=vsHide") ins("| ") ins("| " .. loc[2] .. "") ins("| " .. loc[3]) end ins('|}') end ins("|}") return table.concat(res,"\n") end

return export