Mòdul:el-trans
Aparença
A continuació es mostra la documentació transclosa de la subpàgina /ús. [salta a la caixa de codi]
Mòdul per a la transcripció automàtica del grec al català. Segueix els criteris indicats a w:Transliteració i transcripció de l'alfabet grec segons la proposta feta per l’Associació Catalana de Neohel·lenistes a l’Institut d’Estudis Catalans. L’IEC ha aprovat, el 14 de febrer del 2020, una recomanació de transcripció però no està encara publicada.
És usat per altres mòduls i indirectament per les plantilles {{entrada}}, {{m}} i {{trad}}. Pel grec antic vegeu Mòdul:grc-trans.
local p = {}
local tt = {
["α"] = "a", ["β"] = "v", ["γ"] = "g", ["δ"] = "d",
["ε"] = "e", ["ζ"] = "z", ["η"] = "i", ["θ"] = "th",
["ι"] = "i", ["κ"] = "k", ["λ"] = "l", ["μ"] = "m",
["ν"] = "n", ["ξ"] = "x", ["ο"] = "o", ["π"] = "p",
["ρ"] = "r", ["σ"] = "s", ["ς"] = "s",
["τ"] = "t", ["υ"] = "i", ["φ"] = "f",
["χ"] = "kh", ["ψ"] = "ps", ["ω"] = "o",
["Α"] = "A", ["Β"] = "V", ["Γ"] = "G", ["Δ"] = "D",
["Ε"] = "E", ["Ζ"] = "Z", ["Η"] = "I", ["Θ"] = "Th",
["Ι"] = "I", ["Κ"] = "K", ["Λ"] = "L", ["Μ"] = "M",
["Ν"] = "N", ["Ξ"] = "X", ["Ο"] = "O", ["Π"] = "P",
["Ρ"] = "R", ["Σ"] = "S",
["Τ"] = "T", ["Υ"] = "I", ["Φ"] = "F",
["Χ"] = "Kh", ["Ψ"] = "Ps", ["Ω"] = "O",
[";"] = "?", ["·"] = ";"
}
-- transliterates any words or phrases
function p.tr(text)
if type(text) == "table" then text = text.args[1] end
local gsub = mw.ustring.gsub
local find = mw.ustring.find
local acute = mw.ustring.char(0x301)
local diaeresis = mw.ustring.char(0x308)
local vowels = "[αΑεΕηΗιΙυΥοΟωΩ" .. acute .. diaeresis .. "]"
text = mw.text.trim(text)
text = mw.ustring.toNFD(text)
text = mw.ustring.gsub(text, acute .. diaeresis, diaeresis .. acute)
text = gsub(text, "([βκπτ])([βκπτ])", -- no dobles ββ, κκ, ππ, ττ
function (cons, doble)
if cons == doble then
return cons
end
end)
text = gsub(text, "(.?)([γΓ]ι)", -- γι (inicial) > i
function(before, current)
if before == "" or before == " " or before == "-" then
return current == "Γι" and "I" or "i"
end
end)
text = gsub(text, "γγ(.)", -- γγ > ng(u)
function(following)
if find(following, "[ει]") then
return "ngu" .. following
end
return "ng" .. following
end)
text = gsub(text, "(.?)([γΓ])κ(.)", -- γκ (inicial, medial) > (n)g(u)
function(before, gamma, following)
local ucase = gamma == "Γ"
local cons = ucase and "G" or "g"
if before ~= "" and before ~= " " and before ~= "-" then
cons = ucase and "Ng" or "ng"
end
if find(following, "[ει]") then
return before .. cons .. "u" .. following
end
return before .. cons .. following
end)
text = gsub(text, "γ([ξχ])", "n%1")
text = gsub(text, "μβ", "mb")
text = gsub(text, "(.?)([μΜ])π", -- μπ (inicial o rere consonant, medial) > (m)b
function(before, mi)
local ucase = mi == "Μ"
if before == "" or before == " " or before == "-" or not find(before, vowels) then
return before .. (ucase and "B" or "b")
end
return before .. "mb"
end)
text = gsub(text, "(.?)([νΝ])τ(.?)", -- ντ (inicial o rere consonant, medial) > (n)d, excepte τζ > tz
function(before, ni, following)
local ucase = ni == "Ν"
if before == "" or before == " " or before == "-" or not find(before, vowels) then
return before .. (ucase and "D" or "d") .. following
elseif following ~= "ζ" then
return before .. "nd" .. following
end
end)
text = gsub(text, "(.?)σ(.?)", -- ss entre vocals
function (before, following)
if find(before, vowels) and find(following, vowels) then
return before .. "ss" .. following
end
end)
-- vowels
text = gsub(text, "([αεοΑΕΟ])ι(.?)", -- αι > e, ει > i, οι > i, excepte ϊ
function (vowel, following)
if following ~= diaeresis then
return gsub(vowel, "[αεοΑΕΟ]", {["α"] = "e", ["Α"] = "E", ["ε"] = "i", ["Ε"] = "I", ["ο"] = "i", ["Ο"] = "I"})
.. following
end
end)
text = gsub(text, "([αεΑΕ])υ(.?)", -- αυ > av, ευ > ev, excepte ϋ
function (vowel, following)
if following ~= diaeresis then
return tt[vowel] .. "v" .. following
end
end)
text = gsub(text, "([αεοωΑΕΟΩ])η",
function (vowel)
return tt[vowel] .. "i" .. diaeresis
end)
text = gsub(text, "([οΟ])υ", {["ο"] = "u", ["Ο"] = "U"})
text = gsub(text, ".", tt)
text = gsub(text, "ll", "l·l")
-- regles d'accentuació en català
text = gsub(text, diaeresis, "")
local latin = mw.ustring.toNFC(text)
latin = gsub(latin, "([áÁ])", {["á"]="à", ["Á"]="À"})
local sil = mw.text.split(require("Mòdul:ca-general").sil(latin), '·')
if #sil == 1 then -- monosíl·laba sense accent
latin = gsub(text, acute, "")
elseif find(sil[#sil], "[ÀàÉéÍíÓóÚú]") then -- aguda
if not (find(latin, "[àéíóú]" .. "s?$") or find(latin, "[éí]" .. "n$")) then
text = gsub(text, "([aeoiu][iu])" .. acute, "%1" .. diaeresis)
text = gsub(text, "gui" .. diaeresis, "gui")
latin = gsub(text, acute, "")
end
elseif find(sil[#sil-1], "[ÀàÉéÍíÓóÚú]") then -- plana
if string.find(text, "[aeiou]s?$") or string.find(text, "[ei]n$") then
if not string.find(text, "[aeiou][iu]$") then
text = gsub(text, "([aeoiu][iu])" .. acute, "%1" .. diaeresis)
text = gsub(text, "gui" .. diaeresis, "gui")
latin = gsub(text, acute, "")
end
end
end
return latin
end
return p