Module:Ancient Greek
Appearance
![]() | This Lua module is used on approximately 650 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
Usage
This module transliterates Ancient Greek text. It is based on an old version of the Ancient Greek transliteration module on Wiktionary, with minor modifications to make it callable through a template.
{{#invoke:Ancient Greek|translit|οἷος}}
- hoîos
The code below uses the basic string functions (for instance, str:gsub(...)
) when possible. Ustring functions have to be used when patterns contain sets with multiple-byte characters (for instance, "[αΑ]"
), or quantifiers that act on multiple-byte characters ("α+"
). And they must be used to correctly get a substring of the ith to the jth Unicode character. In other situations, basic string functions can be used, and are preferred for efficiency's sake, as they don't have to parse the string into codepoints before operating on it.
local export = {}
local tt = {
-- Plain vowels
["[αἀᾰ]"] = "a", ["[ΑἈᾸ]"] = "A",
["[άἄ]"] = "á", ["[ΆἌ]"] = "Á",
["[ὰἂ]"] = "à", ["[ᾺἊ]"] = "À",
["[ᾱ]"] = "ā", ["[Ᾱ]"] = "Ā",
["[ᾶἆ]"] = "â", ["[Ἆ]"] = "Â",
["[εἐ]"] = "e", ["[ΕἘ]"] = "E",
["[έἔ]"] = "é", ["[ΈἜ]"] = "É",
["[ὲἒ]"] = "è", ["[ῈἚ]"] = "È",
["[ηἠ]"] = "ē", ["[ΗἨ]"] = "Ē",
["[ήἤ]"] = "ḗ", ["[ΉἬ]"] = "Ḗ",
["[ὴἢ]"] = "ḕ", ["[ῊἪ]"] = "Ḕ",
["[ῆἦ]"] = "ê", ["[Ἦ]"] = "Ê",
["[ιἰῐ]"] = "i", ["[ΙἸῘ]"] = "I",
["[ίἴ]"] = "í", ["[ΊἼ]"] = "Í",
["[ὶἲ]"] = "ì", ["[ῚἺ]"] = "Ì",
["ῑ"] = "ī", ["Ῑ"] = "Ī",
["[ῖἶ]"] = "î", ["[Ἶ]"] = "Î",
["[οὀ]"] = "o", ["[ΟὈ]"] = "O",
["[όὄ]"] = "ó", ["[ΌὌ]"] = "Ó",
["[ὸὂ]"] = "ò", ["[ῸὊ]"] = "Ò",
["[ωὠ]"] = "ō", ["[ΩὨ]"] = "Ō",
["[ώὤ]"] = "ṓ", ["[ΏὬ]"] = "Ṓ",
["[ὼὢ]"] = "ṑ", ["[ῺὪ]"] = "Ṑ",
["[ῶὦ]"] = "ô", ["[Ὦ]"] = "Ô",
["[υὐῠ]"] = "u", ["[ΥῨ]"] = "U",
["[ύὔ]"] = "ú", ["[Ύ]"] = "Ú",
["[ὺὒ]"] = "ù", ["[Ὺ]"] = "Ù",
["ῡ"] = "ū", ["Ῡ"] = "Ū",
["[ῦὖ]"] = "û",
-- Aspirated vowels
["[ἁ]"] = "ha", ["[Ἁ]"] = "Ha",
["[ἅ]"] = "há", ["[Ἅ]"] = "Há",
["[ἃ]"] = "hà", ["[Ἃ]"] = "Hà",
["[ἇ]"] = "hâ", ["[Ἇ]"] = "Hâ",
["[ἑ]"] = "he", ["[Ἑ]"] = "He",
["[ἕ]"] = "hé", ["[Ἕ]"] = "Hé",
["[ἓ]"] = "hè", ["[Ἓ]"] = "Hè",
["[ἡ]"] = "hē", ["[Ἡ]"] = "Hē",
["[ἥ]"] = "hḗ", ["[Ἥ]"] = "Hḗ",
["[ἣ]"] = "hḕ", ["[Ἣ]"] = "Hḕ",
["[ἧ]"] = "hê", ["[Ἧ]"] = "Hê",
["[ἱ]"] = "hi", ["[Ἱ]"] = "Hi",
["[ἵ]"] = "hí", ["[Ἵ]"] = "Hí",
["[ἳ]"] = "hì", ["[Ἳ]"] = "Hì",
["[ἷ]"] = "hî", ["[Ἷ]"] = "Hî",
["[ὁ]"] = "ho", ["[Ὁ]"] = "Ho",
["[ὅ]"] = "hó", ["[Ὅ]"] = "Hó",
["[ὃ]"] = "hò", ["[Ὃ]"] = "Hò",
["[ὡ]"] = "hō", ["[Ὡ]"] = "Hō",
["[ὥ]"] = "hṓ", ["[Ὥ]"] = "Hṓ",
["[ὣ]"] = "hṑ", ["[Ὣ]"] = "Hṑ",
["[ὧ]"] = "hô", ["[Ὧ]"] = "Hô",
["[ὑ]"] = "hu", ["[Ὑ]"] = "Hu",
["[ὕ]"] = "hú", ["[Ὕ]"] = "Hú",
["[ὓ]"] = "hù", ["[Ὓ]"] = "Hù",
["[ὗ]"] = "hû", ["[Ὗ]"] = "Hû",
-- Iota subscript vowels
["[ᾳᾀ]"] = "āi", ["[ᾼᾈ]"] = "Āi",
["[ᾴᾄ]"] = "āí", ["[ᾌ]"] = "Āí",
["[ᾲᾂ]"] = "āì", ["[ᾊ]"] = "Āì",
["[ᾷᾆ]"] = "āî", ["[ᾎ]"] = "Āî",
["[ῃᾐ]"] = "ēi", ["[ῌᾘ]"] = "Ēi",
["[ῄᾔ]"] = "ēí", ["[ᾜ]"] = "Ēí",
["[ῂᾒ]"] = "ēì", ["[ᾚ]"] = "Ēì",
["[ῇᾖ]"] = "ēî", ["[ᾞ]"] = "Ēî",
["[ῳᾠ]"] = "ōi", ["[ῼᾨ]"] = "Ōi",
["[ῴᾤ]"] = "ōí", ["[ᾬ]"] = "Ōí",
["[ῲᾢ]"] = "ōì", ["[ᾪ]"] = "Ōì",
["[ῷᾦ]"] = "ōî", ["[ᾮ]"] = "Ōî",
-- Aspirated iota subscript vowels
["[ᾁ]"] = "hāi", ["[ᾉ]"] = "Hāi",
["[ᾅ]"] = "hāí", ["[ᾍ]"] = "Hāí",
["[ᾃ]"] = "hāì", ["[ᾋ]"] = "Hāì",
["[ᾇ]"] = "hāî", ["[ᾏ]"] = "Hāî",
["[ᾑ]"] = "hēi", ["[ᾙ]"] = "Hēi",
["[ᾕ]"] = "hēí", ["[ᾝ]"] = "Hēí",
["[ᾓ]"] = "hēì", ["[ᾛ]"] = "Hēì",
["[ᾗ]"] = "hēî", ["[ᾟ]"] = "Hēî",
["[ᾡ]"] = "hōi", ["[ᾩ]"] = "Hōi",
["[ᾥ]"] = "hōí", ["[ᾭ]"] = "Hōí",
["[ᾣ]"] = "hōì", ["[ᾫ]"] = "Hōì",
["[ᾧ]"] = "hōî", ["[ᾯ]"] = "Hōî",
-- Diaeresis vowels
["[ϊ]"] = "ï", ["Ϊ"] = "Ï",
["[ΐ]"] = "ḯ",
["[ῒ]"] = "ï̀",
["[ῗ]"] = "ï̂",
["[ϋ]"] = "ü", ["Ϋ"] = "Ü",
["[ΰ]"] = "ǘ",
["[ῢ]"] = "ǜ",
["[ῧ]"] = "ü̂",
-- Consonants
["β"] = "b", ["Β"] = "B",
["γ"] = "g", ["Γ"] = "G",
["δ"] = "d", ["Δ"] = "D",
["ζ"] = "z", ["Ζ"] = "Z",
["θ"] = "th", ["Θ"] = "Th",
["κ"] = "k", ["Κ"] = "K",
["λ"] = "l", ["Λ"] = "L",
["μ"] = "m", ["Μ"] = "M",
["ν"] = "n", ["Ν"] = "N",
["ξ"] = "x", ["Ξ"] = "X",
["π"] = "p", ["Π"] = "P",
["[ρῤ]"] = "r", ["Ρ"] = "R",
["ῥ"] = "rh", ["Ῥ"] = "Rh",
["[σς]"] = "s", ["Σ"] = "S",
["τ"] = "t", ["Τ"] = "T",
["φ"] = "ph", ["Φ"] = "Ph",
["χ"] = "kh", ["Χ"] = "Kh",
["ψ"] = "ps", ["Ψ"] = "Ps",
-- Archaic letters
["ϝ"] = "w", ["Ϝ"] = "W",
["ϻ"] = "ś", ["Ϻ"] = "Ś",
["ϙ"] = "q", ["Ϙ"] = "Q",
["ϡ"] = "š", ["Ϡ"] = "Š",
["ͷ"] = "v", ["Ͷ"] = "V",
-- Diacritics
["[" .. mw.ustring.char(0x0313) .. mw.ustring.char(0x1FBF) .. "]"] = "",
["[" .. mw.ustring.char(0x0314) .. mw.ustring.char(0x1FFE) .. "]"] = "h",
}
local function transliterate(text)
local gsub = mw.ustring.gsub
local find = mw.ustring.find
if find(text, "[ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρςστυφχψω]") == nil then
error("No accentless Greek letters found; is the text actually Ancient Greek?")
end
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éèēêiíìīîoóòōôuúùūû])h([iíìîuúùû])", "h%1%2")
text = gsub(text, "([AÁÀĀÂEÉÈĒÊIÍÌĪÎOÓÒŌÔUÚÙŪÛ])h([iíìîuúùû])", function(c, d)
return "H" .. mw.ustring.lower(c) .. d
end )
return text
end
function export.translit(frame)
local text = frame.args[1]
local transliteration = transliterate(text)
if transliteration then
return "<span title=\"Ancient Greek transliteration\" class=\"Unicode\" style=\"white-space:normal; text-decoration: none\"><i>" .. transliteration .. "</i></span>"
else
return ""
end
end
return export