Module:AFE
I gn a nén co di dzo-pådje /doc pol notule d’ esplikêyes. Clitchîz cial po l’ ahiver.
-- This module makes span AFE for each argument
-- Only use with Modele:AFE as :
-- {{AFE|arg1|arg2|...}}
local p = {}
local builder = require("Module:Builder");
function p.check_ipa(s)
for cp in mw.ustring.gcodepoint( s ) do
if not ( (cp == 32 or cp == 46) or -- Latin Base 0020,002E (space,.)
(cp >= 97 and cp <= 122) or -- Latin Base 0061–007A (a-z)
(cp == 227 or cp == 228) or -- Latin-1 Supplement (ã,ä)
(cp == 230 or cp == 231) or -- Latin-1 Supplement (æ,ç)
(cp == 240 or cp == 245) or -- Latin-1 Supplement (ð,õ AFE ?)
(cp == 248 or cp == 339) or -- Latin-1 Supplement (ø,œ)
(cp == 295 or cp == 297 or cp == 331) or -- Latin Extended-A (ħ,ĩ AFE ?,ŋ)
(cp >= 592 and cp <= 687) or -- IPA Extensions 0250–02AF
(cp >= 688 and cp <= 767) or -- Spacing Modifier Letters 02B0–02FF
(cp >= 768 and cp <= 879) or -- Combining Diacritical Marks 0300–036F
(cp == 946) or -- (β)
(cp == 967) or -- (χ)
(cp >= 7424 and cp <= 7551) or -- Phonetic Extensions 1D00–1D7F
(cp >= 7552 and cp <= 7615) or -- Phonetic Extensions Supplement 1D80–1DBF
(cp == 7869) or -- (ẽ) AFE ?
(cp == 8255) -- (‿)
) then
--mw.log(cp .. " : "..mw.ustring.char(cp))
return false
end
end
return true
end
function p.render(text)
local span = mw.html.create("span")
: attr('class','afe')
: attr('title','Scrijhaedje e l’ alfabet fonetike eternåcionå')
local delimiter = "/"
-- trim white spaces
text = mw.text.trim(text)
-- unicode char U+02C8 for primary stress, not ‹'›
text, n = string.gsub(text, "'", "ˈ")
if(n>0) then
builder.add_category("Årtikes avou coridjaedje otomatike di l' accint tonike dins l' modele AFE")
end
-- unicode char U+02D0 for long sound, not ‹:›
text, n = string.gsub(text, ":", "ː")
if(n>0) then
builder.add_category("Årtikes avou coridjaedje otomatike do crone dins l' modele AFE")
end
-- unicode char U+203F for linking, not ‹_›
text = string.gsub(text, "_", "‿")
-- unicode char U+025B ‹ɛ› , not U+03B5 ‹ε›
text, n = string.gsub(text, "ε", "ɛ")
if(n>0) then
builder.add_category("Årtikes avou coridjaedje otomatike di l' epsilon dins l' modele AFE")
end
-- unicode char U+0261 ‹ɡ› , not ‹g›
text, n = string.gsub(text, "g", "ɡ")
if(n>0) then
builder.add_category("Årtikes avou coridjaedje otomatike do G dins l' modele AFE")
end
-- replace old unofficial ligatures ʦ, ʣ, ʧ, ʤ, ʨ, ʥ
text = string.gsub(text, "ʦ", "t͡s")
text = string.gsub(text, "ʣ", "d͡z")
text = string.gsub(text, "ʧ", "t͡ʃ")
text = string.gsub(text, "ʤ", "d͡ʒ")
text = string.gsub(text, "ʨ", "t͡ɕ")
text = string.gsub(text, "ʥ", "d͡ʑ")
-- ŋ not for gn (ɲ)
-- do we need language code ?
if string.find(mw.title.getCurrentTitle().text, "gn", 1, true)
and string.find(text, 'ŋ', 1, true) then
builder.add_category("Årtikes avou ŋ po GN dins l' modele AFE")
end
-- no treat \.+ or … as AFE
if text == "" or string.find(text, '^%.+$') or text == "…" then
builder.add_category("Årtikes avou des prononçaedjes a radjouter")
builder.add_content('<span class="info">Prononçaedje a radjouter</span>')
return
end
-- if there's no syllable
-- do we need language code ?
if mw.ustring.len(text) > 4
and not string.find(text, '.', 1, true) then
builder.add_category("Årtikes sins sillabe dins l' modele AFE")
end
-- delete / or ] for check_ipa
if string.sub(text, 1, 1) == "[" then
delimiter = "["
text = string.sub(text, 2)
elseif string.sub(text, 1, 1) == "/" then
text = string.sub(text, 2)
end
if string.sub(text, -1)== "/" or
string.sub(text, -1)== "]" then
text = string.sub(text, 1,-2)
end
if not p.check_ipa(text) then
span:addClass('flotche')
builder.add_category("Årtikes avou des flotches dins l' AFE")
end
if delimiter == "[" then
text = "["..text.."]" -- fonetike
else
text = "/"..text.."/" --fonolodjeye
end
span:wikitext(text)
builder.add_content(span)
end
-- Entry point of the module
function p.init(frame)
local html = ''
local i = 0
local dup = {}
builder.init(frame, "Årtikes avou ene flotche dins l' modele AFE")
-- for each argument of the parent modele
local modele = mw.getCurrentFrame():getParent()
for key,val in ipairs(modele.args) do
-- check duplicated arg
if dup[val] ~= nil then
builder.add_category("Årtikes avou des doblons dins l' modele AFE")
else
dup[val] = true
-- white space between each span
if i > 0 then
builder.add_content(" ")
end
p.render(val)
i = i + 1
end
end
return builder.get_content()
end
return p