Module:grc-translit: difference between revisions

From Wiktionary, the free dictionary
Jump to navigation Jump to search
Content deleted Content added
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 Demotic, Greek, Paeonian, Old Ossetic, Oscan, Dacian, 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 of 36 tests failed. (refresh)

TextExpectedActual
testcases for tr function in Module:grc-translit:
Failedλόγοςlógoslogos
Failedσφίγξsphínxsphinx
Failedϝάναξwánaxwanax
Failedοἷαιhoîaihoiai
current problems
FailedΙΧΘΥΣIKHTHUSIChThUS
FailedΥἱός'''Hu'''iós'''U'''hios
u/y
Failedταῦροςtaûrostauros
Failedνηῦςnēûsnēus
Failedσῦςsûssus
Failedὗςhûshus
Failedγυῖονguîonguion
Failedἀναῡ̈τέωanaṻtéōanaṻteō
Failedδαΐφρωνdaḯphrōndaïphrōn
vowel length
Failedτῶνtôntōn
Failedτοὶtoìtoi
Failedτῷtôi
Failedτούτῳtoútōitoutō
Failedσοφίᾳsophíāisophiā
Failedμᾱ̆νόςmānósmā̆nos
h (rough breathing)
Passedhoho
Passedοἱhoihoi
Failedεὕρισκεheúriskeheuriske
Failedὑϊκόςhuïkóshuïkos
Failedπυρρόςpurrhóspurrhos
Failedῥέωrhéōrheō
Failedσάἁμονsáhamonshaamon
capitals
FailedὈδυσσεύςOdusseúsOdusseus
FailedΕἵλωςHeílōsHeilōs
FailedᾍδηςHā́idēsHā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óskalos&nbsp;kai&nbsp;agathos
Failedκαλός καὶ ἀγαθόςkalós&#32;kaì&#32;agathóskalos&#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