This module will transliterate text in the Ethiopic script per WT:ETHI TR. It is used to transliterate Amharic, Blin, Dahalik, Ge'ez, Harari, Chaha, Tigrinya, and Tigre.
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:Ethi-translit/testcases.
tr(text, lang, sc)
text
written in the script specified by the code sc
, and language specified by the code lang
.nil
.local export = {}
local m_str_utils = require("Module:string utilities")
local gsub = m_str_utils.gsub
local tt = {
="hä", ="hu", ="hi", ="ha", ="he", ="hə", ="ho",
="lä", ="lu", ="li", ="la", ="le", ="lə", ="lo",
="lʷa",
="ḥä", ="ḥu", ="ḥi", ="ḥa", ="ḥe", ="ḥə", ="ḥo",
="ḥʷa",
="mä", ="mu", ="mi", ="ma", ="me", ="mə", ="mo",
="mʷa", ="mʲä",
="śä", ="śu", ="śi", ="śa", ="śe", ="śə", ="śo",
="śʷa",
="rä", ="ru", ="ri", ="ra", ="re", ="rə", ="ro",
="rʷa", ="rʲä",
="sä", ="su", ="si", ="sa", ="se", ="sə", ="so",
="sʷa",
="šä", ="šu", ="ši", ="ša", ="še", ="šə", ="šo",
="šʷa",
="ḳä", ="ḳu", ="ḳi", ="ḳa", ="ḳe", ="ḳə", ="ḳo",
="ḳʷä", ="ḳʷi", ="ḳʷa", ="ḳʷe", ="ḳʷə",
="x̣ä", ="x̣u", ="x̣i", ="x̣a", ="x̣e", ="x̣ə", ="x̣o",
="x̣ʷä", ="x̣ʷi", ="x̣ʷa", ="x̣ʷe", ="x̣ʷə",
="bä", ="bu", ="bi", ="ba", ="be", ="bə", ="bo",
="bʷa",
="vä", ="vu", ="vi", ="va", ="ve", ="və", ="vo",
="vʷa",
="tä", ="tu", ="ti", ="ta", ="te", ="tə", ="to",
="tʷa",
="čä", ="ču", ="či", ="ča", ="če", ="čə", ="čo",
="čʷa",
="ḫä", ="ḫu", ="ḫi", ="ḫa", ="ḫe", ="ḫə", ="ḫo",
="ḫʷä", ="ḫʷi", ="ḫʷa", ="ḫʷe", ="ḫʷə",
="nä", ="nu", ="ni", ="na", ="ne", ="nə", ="no",
="nʷa",
="ñä", ="ñu", ="ñi", ="ña", ="ñe", ="ñə", ="ño",
="ñʷa",
="ʾä", ="ʾu", ="ʾi", ="ʾa", ="ʾe", ="ʾə", ="ʾo",
="ʾʷa",
="kä", ="ku", ="ki", ="ka", ="ke", ="kə", ="ko",
="kʷä", ="kʷi", ="kʷa", ="kʷe", ="kʷə",
="xä", ="xu", ="xi", ="xa", ="xe", ="xə", ="xo",
= "xʷə", = "xʷä", = "xʷi", = "xʷa", = "xʷe",
="wä", ="wu", ="wi", ="wa", ="we", ="wə", ="wo",
="ʿä", ="ʿu", ="ʿi", ="ʿa", ="ʿe", ="ʿə", ="ʿo",
="zä", ="zu", ="zi", ="za", ="ze", ="zə", ="zo",
="zʷa",
="žä", ="žu", ="ži", ="ža", ="že", ="žə", ="žo",
="žʷa",
="yä", ="yu", ="yi", ="ya", ="ye", ="yə", ="yo",
="dä", ="du", ="di", ="da", ="de", ="də", ="do",
="dʷa",
="ǧä", ="ǧu", ="ǧi", ="ǧa", ="ǧe", ="ǧə", ="ǧo",
="ǧʷa",
="gä", ="gu", ="gi", ="ga", ="ge", ="gə", ="go",
="gʷä", ="gʷi", ="gʷa", ="gʷe", ="gʷə",
="ŋä", ="ŋu", ="ŋi", ="ŋa", ="ŋe", ="ŋə", ="ŋo",
="ŋʷä", ="ŋʷi", ="ŋʷa", ="ŋʷe", ="ŋʷə",
="ṭä", ="ṭu", ="ṭi", ="ṭa", ="ṭe", ="ṭə", ="ṭo",
="ṭʷa",
="č̣ä", ="č̣u", ="č̣i", ="č̣a", ="č̣e", ="č̣ə", ="č̣o",
="č̣ʷa",
="p̣ä", ="p̣u", ="p̣i", ="p̣a", ="p̣e", ="p̣ə", ="p̣o",
="p̣ʷa",
="ṣä", ="ṣu", ="ṣi", ="ṣa", ="ṣe", ="ṣə", ="ṣo",
="ṣʷa",
="ṣ́ä", ="ṣ́u", ="ṣ́i", ="ṣ́a", ="ṣ́e", ="ṣ́ə", ="ṣ́o",
="fä", ="fu", ="fi", ="fa", ="fe", ="fə", ="fo",
="fʷa", ="fʲä",
="pä", ="pu", ="pi", ="pa", ="pe", ="pə", ="po",
="pʷa",
--punctuation
="§", =" ", =".", =",", =";", =":", =":-", ="?", ="¶",
}
local number = {
=1, =2, =3, =4, =5, =6, =7, =8, =9,
=10, =20, =30, =40, =50, =60, =70, =80, =90
}
function export.number(geez)
local val = 0
if mw.ustring.find(geez, '^') then
geez = '፩' .. geez -- prepend 1
end
geez = gsub(geez, '፼፻', '፼፩፻')
-- following 3 lines are a hack, so that both ፻ and ፼ can be interpreted by the code as "multiply value by 100"
geez = gsub(geez, '፼(*)$', '፼፻%1')
geez = gsub(geez, '፼(*፼)', '፼፻%1')
-- same line again (accounting for overlapping patterns)
geez = gsub(geez, '፼(*፼)', '፼፻%1')
local func = mw.text.gsplit(geez, '')
while true do
local digit = func()
if (not digit) then break end
if mw.ustring.find(digit, '') then
val = val + number
elseif digit == '፻' or digit == '፼' then
val = val * 100
end
end
return val
end
function export.tr(text, lang, sc)
text = (mw.ustring.gsub(text, ".", tt))
-- remove ə that is not in the first syllable
-- *
-- matches one transliterated consonant
local prev_end_pos
local prev_schwa_removed = false
local text_len = mw.ustring.len(text)
text = mw.ustring.gsub(
text,
"()((*)ə)()",
function(start_pos, syllable, consonant, end_pos)
local ret
if (start_pos == 1 or mw.ustring.find(text, "^", start_pos - 1))
or (prev_end_pos == start_pos and prev_schwa_removed
and not (end_pos == text_len + 1 or mw.ustring.find(text, "^", end_pos))) then
ret = syllable
else
ret = consonant
end
prev_schwa_removed = ret == consonant
prev_end_pos = end_pos
return ret
end)
text = mw.ustring.gsub(text, "+", export.number)
text = mw.ustring.gsub(text, "-ʾ", "-")
return text
end
return export