Vai al contenuto

Modulo:GrecoTr

Da Cathopedia, l'enciclopedia cattolica.

La documentazione per questo modulo può essere creata in Modulo:GrecoTr/man

local p = {}

function p.traslittera(frame)
    local testo = frame.args[1] or ""
    if testo == "" then return "" end

    -- Tabella di sostituzione massiva per coprire ogni combinazione di diacritici
    local map = {
        -- Spiriti aspri (aggiungono h)
        ['ἁ']='ha', ['ἑ']='hĕ', ['ἡ']='hē', ['ἱ']='hi', ['ὁ']='hŏ', ['ὑ']='hy', ['ὡ']='hō',
        ['ἅ']='há', ['ἕ']='hé', ['ἥ']='hḗ', ['ἵ']='hí', ['ὅ']='hó', ['ὕ']='hý', ['ὥ']='hṓ',
        ['ἃ']='hà', ['ἓ']='hè', ['ἣ']='hḕ', ['ἳ']='hì', ['ὃ']='hò', ['ὓ']='hỳ', ['ὣ']='hṓ',
        ['ἇ']='hâ', ['ἧ']='hē̂', ['ἷ']='hî', ['ὗ']='hŷ', ['ὧ']='hō̂',
        ['Ἁ']='Ha', ['Ἑ']='Hĕ', ['Ἡ']='Hē', ['Ἱ']='Hi', ['Ὁ']='Hŏ', ['Ὑ']='Hy', ['Ὡ']='Hō',
        ['ῥ']='rh', ['Ῥ']='Rh',

        -- Spiriti dolci (rimossi)
        ['ἀ']='a', ['ἐ']='ĕ', ['ἠ']='ē', ['ἰ']='i', ['ὀ']='ŏ', ['ὐ']='y', ['ὠ']='ō',
        ['ἄ']='á', ['ἔ']='é', ['ἤ']='ḗ', ['ἴ']='í', ['ὄ']='ó', ['ὔ']='ý', ['ὤ']='ṓ',
        ['ἂ']='à', ['ἒ']='è', ['ἢ']='ḕ', ['ἲ']='ì', ['ὂ']='ò', ['ὒ']='ỳ', ['ὢ']='ṑ',
        ['ἆ']='â', ['ἦ']='ē̂', ['ἶ']='î', ['ὖ']='ŷ', ['ὦ']='ō̂',
        ['Ἀ']='A', ['Ἐ']='Ĕ', ['Ἠ']='Ē', ['Ἰ']='I', ['Ὀ']='Ŏ', ['ὐ']='Y', ['Ὠ']='Ō',

        -- Vocali semplici con accenti
        ['ά']='á', ['έ']='é', ['ή']='ḗ', ['ί']='í', ['ό']='ó', ['ύ']='ý', ['ώ']='ṓ',
        ['ὰ']='à', ['ὲ']='è', ['ὴ']='ḕ', ['ὶ']='ì', ['ὸ']='ò', ['ὺ']='ỳ', ['ὼ']='ṑ',
        ['ᾶ']='â', ['ῆ']='ē̂', ['ῖ']='î', ['ῦ']='ŷ', ['ῶ']='ō̂',

        -- Iota sottoscritto (vocal+i)
        ['ᾳ']='ai', ['ῃ']='ēi', ['ῳ']='ōi',
        ['ῷ']='ō̂i', ['ῄ']='ḗi', ['ῲ']='ṑi',

        -- Alfabeto base (distinguendo brevi/lunghe e gamma speciale)
        ['α']='a', ['β']='b', ['δ']='d', ['ε']='ĕ', ['ζ']='z', ['η']='ē', ['θ']='th',
        ['ι']='i', ['κ']='k', ['λ']='l', ['μ']='m', ['ν']='n', ['ξ']='x', ['ο']='ŏ', ['π']='p',
        ['ρ']='r', ['σ']='s', ['ς']='s', ['τ']='t', ['υ']='y', ['φ']='ph', ['χ']='ch', ['ψ']='ps', ['ω']='ō',
        ['Α']='A', ['Β']='B', ['Γ']='G', ['Δ']='D', ['Ε']='Ĕ', ['Ζ']='Z', ['Η']='Ē', ['Θ']='Th',
        ['Ι']='I', ['Κ']='K', ['Λ']='L', ['Μ']='M', ['Ν']='N', ['Ξ']='X', ['Ο']='Ŏ', ['Π']='P',
        ['Ρ']='R', ['Σ']='S', ['Τ']='T', ['Υ']='Y', ['Φ']='Ph', ['Χ']='Ch', ['Ψ']='Ps', ['Ω']='Ō'
    }

    local res = testo

    -- 1. Nessi speciali e Gamma palatale (gh prima di e, i, y)
    res = mw.ustring.gsub(res, "γγ", "ng")
    res = mw.ustring.gsub(res, "γκ", "nk")
    res = mw.ustring.gsub(res, "γχ", "nch")
    res = mw.ustring.gsub(res, "γ[ειηιυ]?", function(m) 
        local map_gh = {['γε']='ghĕ', ['γέ']='ghé', ['γὲ']='ghè', ['γη']='ghē', ['γή']='ghḗ', ['γὴ']='ghḕ', ['γι']='ghi', ['γί']='ghí', ['γὶ']='ghì', ['γυ']='ghy', ['γύ']='ghý', ['γὺ']='ghỳ'}
        return map_gh[m] or m 
    end)
    -- Caso specifico "generale" per gamma
    res = mw.ustring.gsub(res, "γ", "gh") -- lo standard dell'esempio usa 'gh' (es. ghēs)

    -- 2. Dittonghi (evita la scomposizione in vocali brevi separate)
    local dittonghi = {
        ['ου']='ou', ['οὐ']='ou', ['οὑ']='hou', ['οὖ']='oû', ['οὗ']='hoû', ['οὺς']='oùs', ['οῦ']='oû',
        ['αὶ']='aì', ['αί']='aí', ['εὶ']='ĕì', ['εί']='ĕí', ['οὶ']='ŏì', ['οί']='ŏí', ['οῖ']='oî'
    }
    for k, v in pairs(dittonghi) do res = mw.ustring.gsub(res, k, v) end

    -- 3. Sostituzione di tutti i caratteri mappati
    local risultato = ""
    for char in mw.ustring.gmatch(res, ".") do
        risultato = risultato .. (map[char] or char)
    end

    -- 4. Pulizia nessi generati (es: gh + h -> gh)
    risultato = risultato:gsub("ghh", "gh")

    return risultato
end

return p