Mòdul:ca-pron
Aparença
A continuació es mostra la documentació transclosa de la subpàgina /ús. [salta a la caixa de codi]
Mòdul de suport per la plantilla {{ca-pron}}. Vegeu la documentació de la plantilla.
local p = {}
-- dependencies
local m_caIPA = require("Module:ca-pron/AFI") -- generates IPA pronunciation
local m_proncat = require("Module:ca-pron/categories") -- some categories by respelling
local m_general = require('Module:ca-general')
local m_util = require('Module:utilitats')
local lang = {code = "ca", name = "català", sc = "Latn"}
local cframe
local function formatIPA(text, file)
if file then
local ipa = '<span class="IPA" title="àudio de la pronúncia AFI">' .. text .. '</span>'
return cframe:extensionTag{name = 'phonos', content = ipa, args = {file = file}}
end
return '<span class="IPA" title="pronúncia AFI">' .. text .. '</span>'
end
-- agrupació de pronúncies idèntiques o amb al·lòfons
local function groupPronunsByDialect(var)
local alloph_match = "[βðɣɾ]"
local alloph_sub = {["β"] = "b", ["ð"] = "d", ["ɣ"] = "ɡ", ["ɫ"] = "l", ["ɾ"] = "r"}
local fon = {}
for k, v in pairs(var) do
fon[k] = mw.ustring.gsub(v, alloph_match, alloph_sub)
end
for k, v in pairs(fon) do
if string.sub(k, -1) == "2" and v == fon[string.sub(k, 1, -2)] then
var[k] = nil
end
end
if fon.noc == fon.val and fon.noc2 == fon.val2 then
var.occ = var.val
var.occ2 = var.val2
fon.occ = fon.val
fon.occ2 = fon.val2
var.noc = nil
var.noc2 = nil
var.val = nil
var.val2 = nil
end
if var.gir == nil and var.sep == nil and var.alg == nil
and fon.cen == fon.bal and fon.cen2 == fon.bal2
then
var.ori = var.cen
var.ori2 = var.cen2
fon.ori = fon.cen
fon.ori2 = fon.cen2
var.cen = nil
var.cen2 = nil
var.bal = nil
var.bal2 = nil
end
if fon.ori == fon.occ and fon.ori2 == fon.occ2 then
var.gen = var.ori
var.gen2 = var.ori2
var.ori = nil
var.ori2 = nil
var.occ = nil
var.occ2 = nil
end
return var
end
-- get arguments of audio files
local function getAudioFiles(pron, args, categories)
local audio = {}
local map_files = {["cen"]="f-centr", ["cen2"]="f-centr2", ["ceng"]="f-gir",
["bal"]="f-bal", ["bal2"]="f-bal2",
["sep"]="f-sept", ["alg"]="f-alg",
["noc"]="f-nocc", ["noc2"]="f-nocc2", ["val"]="f-val", ["val2"]="f-val2",
["inf"]="f-inf", ["inf2"]="f-inf2", ["inf3"]="f-inf3"}
for a, f in pairs(map_files) do
audio[a] = args[f]
end
-- match audio with pron accent
if next(audio) then
if pron.gir and not pron.cen2 then
audio.cen2 = audio.cen2 or audio.gir
end
if pron.cen and not pron.cen2 then
audio.cen = audio.cen or audio.cen2
end
if pron.bal and not pron.bal2 then
audio.bal = audio.bal or audio.bal2
end
if pron.noc and not pron.noc2 then
audio.noc = audio.noc or audio.noc2
end
if pron.val and not pron.val2 then
audio.val = audio.val or audio.val2
end
if pron.ori then
audio.ori = audio.cen or audio.bal
if not pron.ori2 then
audio.ori = audio.ori or audio.cen2 or audio.bal2 or audio.sep or audio.alg
else
audio.ori2 = audio.cen2 or audio.bal2
end
end
if pron.occ then
audio.occ = audio.val or audio.noc
if not pron.occ2 then
audio.occ = audio.occ or audio.val2 or audio.noc2
else
audio.occ2 = audio.val2 or audio.noc2
end
end
if pron.gen then
audio.gen = audio.cen or audio.val or audio.bal or audio.noc
or audio.cen2 or audio.val2 or audio.bal2 or audio.noc2
end
categories = categories .. m_util.format_categories({"Termes en català amb àudio"}, lang)
end
return audio, categories
end
-- Entry point for template:ca-pron
function p.plantilla(frame)
cframe = frame
local args = frame:getParent().args
local pagename = args.pagename or mw.ustring.lower(mw.title.getCurrentTitle().subpageText)
local namespace = mw.title.getCurrentTitle().nsText
-- get pronunciation arguments
local pron = {}
-- change arguments with abreviation to 3-letter plus variant for easier handling
local map_pron_args = {["gen"] = 1, ["gen2"] = 2,
["ori"]="or", ["ori2"]="or2", ["occ"]="occ", ["occ2"]="occ2",
["cen"]="centr", ["cen2"]="centr2", ["ceng"]="gir",
["bal"]="bal", ["bal2"]="bal2",
["sep"]="sept", ["alg"]="alg",
["noc"]="nocc", ["noc2"]="nocc2", ["val"]="val", ["val2"]="val2"}
for p, a in pairs(map_pron_args) do
if args[a] then
pron[p] = mw.text.trim(args[a])
end
end
-- track explicited IPA to be moved to automatic with respelling
-- except "sep" and "alg" currently not suported
for lect, p in pairs(pron) do
if not (string.sub(lect, -3) == "sep" or string.sub(lect, -3) == "alg") then
if p and string.find(p, "/") then
m_util.track("ca-pron/AFI")
break
end
end
end
local heading = ':*<span style="font-weight: bold;">Pronúncia</span><sup>[[Viccionari:Pronúncia del català|(i)]]</sup>: '
-- generate IPA
local pron_IPA, text_error
pron[1] = pron.gen or "+"
pron[2] = pron.gen2
local pos = args.tipus
pron_IPA, text_error = m_caIPA.show(pron, pagename, pos)
if text_error then
text_error = heading .. "(Error: " .. text_error .. ")"
if namespace == "" then
text_error = text_error .. m_util.format_categories({"Entrades en català amb pronúncia pendent"}, lang)
end
return text_error
end
local categories = ""
if pron.gen and not string.find(pron.gen, "/") then
if string.find(pron.gen, "[^,]yll") then
m_util.track("ca-pron/yll")
end
categories = m_proncat.getCat(pron.gen, pagename)
end
pron = groupPronunsByDialect(pron_IPA)
pron.inf = args["informal"]
pron.infq = args["inf_q"]
pron.inf2 = args["informal2"]
pron.inf2q = args["inf2_q"]
pron.inf3 = args["informal3"]
pron.inf3q = args["inf3_q"]
pron.rima = args["rima"]
pron.q = args["q"]
if pron.inf then
m_util.track("ca-pron/informal")
end
-- get audio files by pron
local audio = {}
audio, categories = getAudioFiles(pron, args, categories)
-- Formatting
local ret = {heading}
if pron.q then
table.insert(ret, '(' .. pron.q .. ') ')
end
local pron_order = {"gen", "ori", "cen", "ceng", "bal", "sep", "alg",
"occ", "noc", "val", "inf"}
local pron_labels = {["gen"]="",
["ori"]="oriental", ["cen"]="central", ["ceng"]="(gironí)",
["bal"]="balear", ["sep"]="septentrional", ["alg"]="alguerès",
["occ"]="occidental", ["noc"]="nord-occidental", ["val"]="valencià",
["inf"]=pron.infq, ["inf2"]=pron.inf2q, ["inf3"]=pron.inf3q }
local dialect_groups = {
["ori"] = {"cen", "ceng", "bal", "sep", "alg"},
["occ"] = {"noc", "val"}}
-- format inline for ori+occ, format table if ori or occ > 1
local inline = true
local dialect_groups_num = {}
for group, lects in pairs(dialect_groups) do
local num_pron = 0
if pron[group] then
dialect_groups_num[group] = 1
else
for _, lect in ipairs(lects) do
if pron[lect] then
num_pron = num_pron + 1
end
end
dialect_groups_num[group] = num_pron
if num_pron > 1 then
inline = false
end
end
end
local comma = false
if inline then
for i, v in ipairs(pron_order) do
if pron[v] then
if v == "inf" then
table.insert(ret, '\n:: Informal: ')
comma = false
end
table.insert(ret, (comma and ', ' or '') .. (pron_labels[v] or '') .. ' ' .. formatIPA(pron[v], audio[v]))
if pron[v .. "2"] then
table.insert(ret, ', ' .. (pron_labels[v .. "2"] or '') .. ' ' .. formatIPA(pron[v .. "2"], audio[v .. "2"]))
if pron[v .. "3"] then
table.insert(ret, ', ' .. (pron_labels[v .. "3"] or '') .. ' ' .. formatIPA(pron[v .. "3"], audio[v .. "3"]))
end
end
comma = true
end
end
else
local pron_line = 0
table.insert(ret, '\n::{| cellpadding="0" cellspacing="0"')
for i, v in ipairs(pron_order) do
if v == "ori" and dialect_groups_num[v] > 0 then
table.insert(ret, '\n|-\n| Oriental: ||')
comma = false
pron_labels["ori"] = ""
elseif v == "occ" and dialect_groups_num[v] > 0 then
table.insert(ret, '\n|-\n| Occidental: ||')
comma = false
pron_labels["occ"] = ""
pron_line = 0
elseif v == "inf" and pron.inf then
table.insert(ret, '\n|-\n| Informal: ||')
comma = false
pron_line = 0
end
if pron[v] then
if v ~= "ceng" and pron_line + (pron[v .. "2"] and 2 or 1) > 2 then
table.insert(ret, '\n|-\n| ||')
comma = false
pron_line = 0
end
table.insert(ret, (comma and ', ' or '') .. (pron_labels[v] or '') .. ' ' .. formatIPA(pron[v], audio[v]))
pron_line = pron_line + 1
if pron[v .. "2"] then
table.insert(ret, ', ' .. (pron_labels[v .. "2"] or '') .. ' ' .. formatIPA(pron[v .. "2"], audio[v .. "2"]))
pron_line = pron_line + 1
if pron[v .. "3"] then
table.insert(ret, ', ' .. (pron_labels[v .. "3"] or '') .. ' ' .. formatIPA(pron[v .. "3"], audio[v .. "3"]))
pron_line = pron_line + 1
end
end
comma = true
end
end
table.insert(ret, '\n|}')
end
table.insert(ret, categories)
-- Rimes
-- formes generals per català occidental
if pron.val2 and (mw.ustring.find(pron.val2, "v") or mw.ustring.find(pron.val2, "ŋk")) then
pron.val = pron.val2
end
if mw.ustring.find(pron.noc or '', "ˈ.*i%.d͡z") and mw.ustring.find(pron.val or '', "ˈ.*i%.z") then
pron.occ = pron.noc
elseif mw.ustring.find(pron.noc or '', "ˈ.*[^͡]ʒ") and mw.ustring.find(pron.val or '', "ˈ.*d͡ʒ") then
pron.occ = mw.ustring.gsub(pron.val, "d͡ʒ", "ʒ")
elseif mw.ustring.find(pron.occ or '', "ɫ%.ɫ") then
pron.occ2 = nil
end
local pronrima = pron.rima or pron.occ2 or pron.occ or pron.val or pron.noc or pron.bal or pron.ori or pron.gen2 or pron.gen
-- sense locucions ni prefixos o sufixos ni àtons
if pronrima and pronrima ~= "" and not (string.find(pagename, "[^ ]+ [^ ]+") or string.find(pagename, "^-") or string.find(pagename, "-$") or not string.find(pronrima, "ˈ") or namespace ~= "") then
pronrima = mw.ustring.gsub(pronrima, "[/%[%]]", "")
local pronrimaor = pron.cen or pron.ori or ''
pronrimaor = mw.ustring.gsub(pronrimaor, "[/%[%]]", "")
if mw.ustring.find(pronrima, "[rɾ]s?$") and pronrimaor ~= "" and not mw.ustring.find(pronrimaor, "[rɾ]s?$") then
pronrima = mw.ustring.gsub(pronrima, "[rɾ](s?)$", "(ɾ)%1")
end
-- número de síl·labes per ordenar categoria de rimes
pronrima = mw.ustring.gsub(pronrima, "^[ˈˌ]", "")
local _, numsil = mw.ustring.gsub(pronrima, "[.ˌˈ]", "")
numsil = numsil + 1
-- inici des de l'accent
local posaccent = mw.ustring.find(pronrima, "ˈ") or 0
pronrima = mw.ustring.sub(pronrima, posaccent + 1)
pronrima = mw.ustring.gsub(pronrima, "%.", "")
posaccent = mw.ustring.find(pronrimaor, "ˈ") or 0
pronrimaor = mw.ustring.sub(pronrimaor, posaccent + 1)
-- inici des de la vocal accentuada
local vocals = m_util.llista({'a','e','ɛ','i','o','ɔ','u'})
local rima = ''
for i = 1, mw.ustring.len(pronrima) do
if vocals[mw.ustring.sub(pronrima, i, i)] then
rima = mw.ustring.sub(pronrima, i)
break
end
end
local rimaor = ''
for i = 1, mw.ustring.len(pronrimaor) do
if vocals[mw.ustring.sub(pronrimaor, i, i)] then
rimaor = mw.ustring.sub(pronrimaor, i)
break
end
end
-- substitució d'aproximants
local from_pron = 'βðɣɫ͡'
local to_pron = 'bdɡl'
for j = 1, mw.ustring.len(from_pron) do
rima = mw.ustring.gsub(rima, mw.ustring.sub(from_pron, j, j), mw.ustring.sub(to_pron, j, j) or '')
end
rima = mw.ustring.gsub(rima, "r([^aeiou])", "ɾ%1")
rima = mw.ustring.gsub(rima, "r$", "ɾ")
if mw.ustring.find(rima, "^e") and mw.ustring.find(rimaor, "^ɛ") then
rima = mw.ustring.gsub(rima, "^e", "ɛ")
end
local textrima = p.rima(rima, numsil)
if textrima ~= '' then
table.insert(ret, '\n' .. textrima)
end
end
return table.concat(ret)
end
-- Funció d'entrada de la plantilla:ca-rima i auxiliar de ca-pron
function p.rima(rima, numsil)
if type(rima) == "table" then
local args = rima:getParent().args
rima = args[1] or ''; if rima == '' then rima = '-' end
numsil = tonumber(args[2] or '0')
end
-- rimes migrades a categoria
local ret = ''
if mw.title.new("Categoria:Rimes en català -" .. rima).exists then
ret = ':*<span style="font-weight: bold;">Rimes</span>: [[:Categoria:Rimes en català -' .. rima .. '|-' .. rima .. ']]'
local sorting = numsil
if sorting > 9 then
sorting = ">"
else
sorting = tostring(numsil)
end
sorting = sorting .. m_general.ordena()
ret = ret .. m_util.format_categories({'Rimes en català -' .. rima}, lang, sorting)
else
m_util.track("rimes/" .. rima)
end
return ret
end
return p