Module:el-translit
Jump to navigation
Jump to search
- The following documentation is located at Module:el-translit/documentation. [edit] Categories were auto-generated by Module:module categorization. [edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
This module will transliterate Greek language text per WT:EL TR. It is also used to transliterate Cappadocian Greek, Pontic Greek, Tsakonian, and Thracian.
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:el-translit/testcases.
Functions
tr(text, lang, sc)
- Transliterates a given piece of
text
written in the script specified by the codesc
, and language specified by the codelang
. - When the transliteration fails, returns
nil
.
local m_str_utils = require("Module:string utilities")
local gsub = m_str_utils.gsub
local sub = m_str_utils.sub
local U = m_str_utils.char
local acute = U(0x301)
local diaeresis = U(0x308)
local erotimatiko = U(0x37E)
local export = {}
local tt = {
["α "] = "a", ["ά"] = "á", ["β "] = "v", ["γ "] = "g", ["δ "] = "d",
["ε "] = "e", ["έ"] = "é", ["ζ "] = "z", ["η "] = "i", ["ή"] = "í",
["θ "] = "th", ["ι "] = "i", ["ί"] = "í", ["ϊ"] = "ï", ["ΐ"] = "ḯ",
["κ "] = "k", ["λ "] = "l", ["μ "] = "m", ["ν "] = "n", ["ξ "] = "x",
["ο "] = "o", ["ό"] = "ó", ["π "] = "p", ["ρ "] = "r", ["σ "] = "s",
["ς"] = "s", ["τ "] = "t", ["υ "] = "y", ["ύ"] = "ý", ["ϋ"] = "ÿ",
["ΰ"] = "ÿ́", ["φ "] = "f", ["χ "] = "ch", ["ψ "] = "ps", ["ω "] = "o",
["ώ"] = "ó",
["Α "] = "A", ["Ά"] = "Á", ["Β "] = "V", ["Γ "] = "G", ["Δ "] = "D",
["Ε "] = "E", ["Έ"] = "É", ["Ζ "] = "Z", ["Η "] = "I", ["Ή"] = "Í",
["Θ "] = "Th", ["Ι "] = "I", ["Ί"] = "Í", ["Κ "] = "K", ["Λ "] = "L",
["Μ "] = "M", ["Ν "] = "N", ["Ξ "] = "X", ["Ο "] = "O", ["Ό"] = "Ó",
["Π "] = "P", ["Ρ "] = "R", ["Σ "] = "S", ["Τ "] = "T", ["Υ "] = "Y",
["Ύ"] = "Ý", ["Φ "] = "F", ["Χ "] = "Ch", ["Ψ "] = "Ps", ["Ω "] = "O",
["Ώ"] = "Ó",
-- punctuation
["·"] = ";",
}
-- transliterates any words or phrases
function export.tr(text, lang, sc)
text = gsub(gsub(text, "χ ̌", "š"), "Χ ̌", "Š") -- dialectal
text = gsub(gsub(text, "ά̤", "ä́"), "Ά̤", "Ä́") -- dialectal
text = gsub(gsub(text, "α ̤", "ä"), "Α ̤", "Ä") -- dialectal
text = gsub(gsub(text, "ό̤", "ö́"), "Ό̤", "Ö́") -- dialectal
text = gsub(gsub(text, "ο ̤", "ö"), "Ο ̤", "Ö") -- dialectal
text = gsub(text, "([^A-Za-z0-9])[;" .. erotimatiko .. "]", "%1?")
text = gsub(text, "([α ε η Α Ε Η ])([υύ])()",
function (vowel, upsilon, position)
-- Find next character that is not whitespace or punctuation.
local following = ""
while true do
local next = sub(text, position, position)
if next == "" then -- reached end of string
break
elseif next:find "[%s%p]" then
position = position + 1
else
following = next
break
end
end
return tt[vowel]
.. (upsilon == "ύ" and acute or "")
.. ((following == "" or ("θκξπσςτφχψ"):find(following, 1, true)) and "f" or "v")
end)
text = gsub(text, "([αεοωΑΕΟΩ])([ηή])",
function (vowel, ita)
if ita == "ή" then
return tt[vowel] .. "i" .. diaeresis .. acute
else
return tt[vowel] .. "i" .. diaeresis
end
end)
text = gsub(text, "[ω Ω ][ιί]",
{["ω ι "] = "oï", ["ωί"] = "oḯ",
["Ω ι "] = "Oï", ["Ωί"] = "Oḯ"})
text = gsub(text, "[ο Ο ][υύ]",
{["ο υ "] = "ou", ["ού"] = "oú",
["Ο υ "] = "Ou", ["Ού"] = "Oú"})
text = gsub(text, "(.?)([μ Μ ])π ",
function (before, mi)
if before == "" or before == " " or before == "-" then
if mi == "Μ " then
return before .. "B"
else
return before .. "b"
end
end
end)
text = gsub(text, "γ ([γ ξ χ ])", "n%1")
text = gsub(text, ".", tt)
return text
end
return export