Module:grc-translit: difference between revisions

Definition from Wiktionary, the free dictionary
Jump to navigation Jump to search
(Created page with "--Transliteration for Ancient Greek. local export = {} local tt = { -- Vowels ["[αάὰᾶἀἄἂἆᾰ]"] = "a", ["[ἁἅἃἇ]"] = "ha", ["[ᾱᾳ...")
 
(fix cases where <h> wrongly appeared mid-diphthong, per Wiktionary:Grease pit/2013/September#Ancient Greek transliteration)
Line 68: Line 68:
   
 
local gsub = mw.ustring.gsub
 
local gsub = mw.ustring.gsub
 
text = gsub(text, "[οόὸὀὄὂ][ὑὕὓὗ]", "hou")
 
text = gsub(text, "[ΟΌῸὈὌὊ][ὑὕὓὗὙὝὛὟ]", "Hou")
 
   
 
text = gsub(text, "γ([γκξχ])", "n%1")
 
text = gsub(text, "γ([γκξχ])", "n%1")
Line 79: Line 76:
 
text = gsub(text, regex, repl)
 
text = gsub(text, regex, repl)
 
end
 
end
  +
 
text = gsub(text, "([aāeēioōu])h", "h%1")
  +
text = gsub(text, "([AĀEĒIOŌU])h", function (c)
  +
return "H" .. mw.ustring.lower(c)
  +
end)
   
 
return text
 
return text

Revision as of 07:44, 7 October 2013

This module will transliterate Ancient Greek language text per WT:GRC TR. It is also used to transliterate Cappadocian Greek, Paeonian, Old Ossetic, Pontic Greek, Ancient Macedonian, and Phrygian.

The module should preferably not be called directly from templates or other modules. To use it from a template, use {{xlit}}. Within a module, use Module:languages#Language:transliterate.

For testcases, see Module:grc-translit/testcases.

Functions

tr(text, lang, sc)
Transliterates a given piece of text written in the script specified by the code sc, and language specified by the code lang. When the transliteration fails, returns nil.

34 tests failed. (refresh)

Text Expected Actual
testcases for tr function in Module:grc-translit:
Failed λόγος lógos logos
Failed σφίγξ sphínx sphinx
Failed ϝάναξ wánax wanax
Failed οἷαι hoîai hoiai
current problems
Failed ΙΧΘΥΣ IKHTHUS IChThUS
Failed Υἱός '''Hu'''iós '''U'''hios
u/y
Failed ταῦρος taûros tauros
Failed νηῦς nēûs nēus
Failed σῦς sûs sus
Failed ὗς hûs hus
Failed γυῖον guîon guion
Failed ἀναῡ̈τέω anaṻtéō anaṻteō
Failed δαΐφρων daḯphrōn daïphrōn
vowel length
Failed τῶν tôn tōn
Failed τοὶ toì toi
Failed τῷ tôi
Failed τούτῳ toútōi toutō
Failed σοφίᾳ sophíāi sophiā
Failed μᾱ̆νός mānós mā̆nos
h (rough breathing)
Passed ho ho
Passed οἱ hoi hoi
Failed εὕρισκε heúriske heuriske
Failed ὑϊκός huïkós huïkos
Failed πυρρός purrhós purrhos
Failed ῥέω rhéō rheō
Failed σάἁμον sáhamon shaamon
capitals
Failed Ὀδυσσεύς Odusseús Odusseus
Failed Εἵλως Heílōs Heilōs
Failed ᾍδης Hā́idēs Hādēs
Failed ἡ Ἑλήνη hē Helḗnē hē Helēnē
punctuation
Failed ἔχεις μοι εἰπεῖν, ὦ Σώκρατες, ἆρα διδακτὸν ἡ ἀρετή; ékheis moi eipeîn, ô Sṓkrates, âra didaktòn hē aretḗ? echeis moi eipein, ō Sōkrates, ara didakton hē aretē;
Failed τί τηνικάδε ἀφῖξαι, ὦ Κρίτων; ἢ οὐ πρῲ ἔτι ἐστίν; tí tēnikáde aphîxai, ô Krítōn? ḕ ou prṑi éti estín? ti tēnikade aphixai, ō Kritōn; ē ou prō eti estin;
Failed τούτων φωνήεντα μέν ἐστιν ἑπτά· α ε η ι ο υ ω. toútōn phōnḗenta mén estin heptá; a e ē i o u ō. toutōn phōnēenta men estin hepta· a e ē i o u ō.
Failed πήγ(νῡμῐ) pḗg(nūmi) pēg(nūmi)
HTML entities
Failed καλός καὶ ἀγαθός kalós&nbsp;kaì&nbsp;agathós kalos&nbsp;kai&nbsp;agathos
Failed καλός καὶ ἀγαθός kalós&#32;kaì&#32;agathós kalos&#32;kai&#32;agathos

--[[
Transliteration for Ancient Greek.
]]

local export = {}

local tt = {
	-- Vowels
    ["[αάὰᾶἀἄἂἆᾰ]"] = "a",
    ["[ἁἅἃἇ]"] = "ha",
    ["[ᾱᾳᾴᾲᾷᾀᾄᾂᾆ]"] = "ā",
    ["[ᾁᾅᾃᾇ]"] = "hā",
    ["[εέὲἐἔἒ]"] = "e",
    ["[ἑἕἓ]"] = "he",
    ["[ηήὴῆἠἤἢἦῃῄῂῇᾐᾔᾒᾖ]"] = "ē",
    ["[ἡἥἣἧᾑᾕᾓᾗ]"] = "hē",
    ["[ιίὶῖἰἴἲἶῐ]"] = "i",
    ["[ἱἵἳἷ]"] = "hi",
    ["[ϊΐῒῗ]"] = "ï",
    ["ῑ"] = "ī",
    ["[οόὸὀὄὂ]"] = "o",
    ["[ὁὅὃ]"] = "ho",
    ["[υύὺῦὐὔὒὖῠ]"] = "u",
    ["[ὑὕὓὗ]"] = "hu",
    ["[ϋΰῢῧ]"] = "ü",
    ["ῡ"] = "ū",
    ["[ωώὼῶὠὤὢὦῳῴῲῷᾠᾤᾢᾦ]"] = "ō",
    ["[ὡὥὣὧᾡᾥᾣᾧ]"] = "hō",

    ["[ΑΆᾺἈἌἊἎᾸ]"] = "A",
    ["[ἉἍἋἏ]"] = "Ha",
    ["[Ᾱᾼᾈᾌᾊᾎ]"] = "Ā",
    ["[ᾉᾍᾋᾏ]"] = "Hā",
    ["[ΕΈῈἘἜἚ]"] = "E",
    ["[ἙἝἛ]"] = "He",
    ["[ΗΉῊἨἬἪἮῌᾘᾜᾚᾞ]"] = "Ē",
    ["[ἩἭἫἯᾙᾝᾛᾟ]"] = "Hē",
    ["[ΙΊῚἸἼἺἾῘ]"] = "I",
    ["[ἹἽἻἿ]"] = "Hi",
    ["Ϊ"] = "Ï",
    ["Ῑ"] = "Ī",
    ["[ΟΌῸὈὌὊ]"] = "O",
    ["[ὉὍὋ]"] = "Ho",
    ["[ΥΎῪῨ]"] = "U",
    ["[ὙὝὛὟ]"] = "Hu",
    ["Ϋ"] = "Ü",
    ["Ῡ"] = "Ū",
    ["[ΩΏῺὨὬὪὮῼᾨᾬᾪᾮ]"] = "Ō",
    ["[ὩὭὫὯᾩᾭᾫᾯ]"] = "Hō",

    -- Consonants
    ["β"] = "b",  ["γ"] = "g",  ["δ"] = "d",  ["ζ"] = "z",  ["θ"] = "th", ["κ"] = "k",
    ["λ"] = "l",  ["μ"] = "m",  ["ν"] = "n",  ["ξ"] = "x",  ["π"] = "p",  ["σ"] = "s",
    ["τ"] = "t",  ["φ"] = "ph", ["χ"] = "ch", ["ψ"] = "ps", ["ῥ"] = "rh", ["[ρῤ]"] = "r",
    ["ς"] = "s",
    ["Β"] = "B",  ["Γ"] = "G",  ["Δ"] = "D",  ["Ζ"] = "Z",  ["Θ"] = "Th", ["Κ"] = "K",
    ["Λ"] = "L",  ["Μ"] = "M",  ["Ν"] = "N",  ["Ξ"] = "X",  ["Π"] = "P",  ["Σ"] = "S",
    ["Τ"] = "T",  ["Φ"] = "Ph", ["Χ"] = "Ch", ["Ψ"] = "Ps", ["Ῥ"] = "Rh", ["Ρ"] = "R",
    
    -- Archaic
    ["ϝ"] = "w",  ["ϻ"] = "ś",  ["ϙ"] = "q",  ["ϡ"] = "š",
    ["Ϝ"] = "W",  ["Ϻ"] = "Ś",  ["Ϙ"] = "Q",  ["Ϡ"] = "Š",
}

-- Takes a text and return the transliterated form.
function export.tr(text)
    if type(text) == 'table' then text = text.args[1] end

    local gsub = mw.ustring.gsub

    text = gsub(text, "γ([γκξχ])", "n%1")

    text = gsub(text, "ρρ", "rrh")

    for regex, repl in pairs(tt) do
        text = gsub(text, regex, repl)
    end

    text = gsub(text, "([aāeēioōu])h", "h%1")
    text = gsub(text, "([AĀEĒIOŌU])h", function (c)
    	return "H" .. mw.ustring.lower(c)
    end)

    return text
end

return export