Module:frp-IPA

local m_link = require("Module:links") local frp = require("Module:languages").getByCode("frp") local m_IPA = require("Module:IPA") local format_accent = require("Module:accent qualifier").format_qualifiers local locs = mw.loadData("Module:frp-IPA/data")

local export = {}

local accents = mw.loadData("Module:labels/data/lang/frp")

local codes = {"cmt", "nch", "frb", "vds", "vls", "vld", "pms", "svy", "gnv", "bgs", "brs", "dmb", "bjl", "lyn", "frz", "dph", "apl"} local allowed_codes = require("Module:table/listToSet")(codes) allowed_codes.ALF = true allowed_codes.AIS = true export.codes = codes

-- alf:17/6;ais:822 local function make_ref(alf,ais) local alf_res, ais_res if alf and alf ~= "" then local alf_url, alf_display = alf:match("^(%d+)/(%d+)$") if not alf_url then error("Invalid format for ALF: " .. alf) end alf_res = "ALF map "..alf_display.."" end if ais and ais ~= "" then if not ais:match("^%d+$") then error("Invalid format for AIS: " .. ais) end ais_res = "AIS map "..ais.."" end if alf_res or ais_res then return "(Transcribed from "..table.concat({alf_res, ais_res}, " and ") .. ")\n" end return "" end

local function record(data,field) return function(value) if value ~= "" then data[field] = value end return "" end end

-- format: "[pron] (loc1,loc2,...)" (ortho and loc optional) local function parse(text,loc) local data = {} text = text:gsub("[/%[][^/%[%]]+[/%]]",record(data,"pron")) if not data.pron then error("Missing pronunciation in "..loc) end text = text:gsub("^<([^<>]+)>",record(data,"ortho")) text = text:gsub("^%(([^%(%)]+)%)",record(data,"locs")) if text ~= "" then error("Invalid input ("..loc.."): "..text) end return data end

local function format_ortho(frp, text) if text then return " ⟨" .. m_link.full_link({lang = frp, term = text}) .. "⟩"	end return "" end

local function parse_loc(group,code) local data = locs[group][code] if not data then error("Invalid code " .. code .. " for " .. accents[group]) end if type(data) == "string" then -- allow redirect once code,data = data,locs[group][data] end local wiki = (type(data) == "table") and data.wiki or code return {wiki, code, frp:makeSortKey(code)} end

local function format_locs(group,text) if not text then return "" end local locs = mw.text.split(text,",",true) for i,loc in ipairs(locs) do		locs[i] = parse_loc(group,loc) end table.sort(locs,function(a,b) return a[3]<b[3] end) for i,loc in ipairs(locs) do		locs[i] = ""..loc[2].."" end return " (" .. table.concat(locs,", ") .. ")" end

function export.show(frame) local args = frame:getParent.args -- check if each parameter name is valid for a,_ in pairs(args) do		if type(a) == "number" then error("This template does not accept numbered arguments.") end if not allowed_codes[a] then error("Invalid accent code: "..a)		end end -- reference local ref = make_ref(args.ALF, args.AIS) -- go through each lect in order local show = {} local hide = {} for _,a in ipairs(codes) do		if args[a] and args[a] ~= "" then local accent = format_accent(frp,{a}) table.insert(hide,'* '..accent) local terms = mw.text.split(args[a],";",true) local prons = {} for _,term in ipairs(terms) do				local data = parse(term, a)				table.insert(prons,{pron = data.pron}) local hide_text = m_IPA.format_IPA(frp, data.pron) .. format_ortho(frp, data.ortho) .. format_locs(a, data.locs) table.insert(hide,'** '..hide_text) end table.insert(show,'* '..accent..': '..m_IPA.format_IPA_multiple(frp, prons, nil, 1)) end end return ref .. ' '		.. ' '		.. ' \n' .. table.concat(show,'\n') .. '\n \n' .. table.concat(hide,'\n') .. ' ' end

return export