local export = {}
local gsub = mw.ustring.gsub
local lower = mw.ustring.lower
local trim = mw.text.trim
local letters = {
="A", ="B", ="V", ="G", ="D", ="E", ="O", ="Ž", ="Z", ="I", ="J",
="K", ="L", ="M", ="N", ="O", ="P", ="R", ="S", ="T", ="U", ="F",
="H", ="C", ="Č", ="Š", ="Šč", ="Ə", ="I", ="", ="E", ="U", ="A",
="a", ="b", ="v", ="g", ="d", ="e", ="o", ="ž", ="z", ="i", ="j",
="k", ="l", ="m", ="n", ="o", ="p", ="r", ="s", ="t", ="u", ="f",
="h", ="c", ="č", ="š", ="šč", ="ə", ="i", ="", ="e", ="u", ="a",
}
local palatals = {
="Ď", = "Ź", = "Ľ", = "Ń", = "Ŕ", = "Ś", = "Ť", = "Ć",
="ď", = "ź", = "ľ", = "ń", = "ŕ", = "ś", = "ť", = "ć",
}
local vowels = "АОУЫЭЯЁЮИЕЬаоуыэяёюиеь"
local front = "ЕЁИЮЯеёиюя"
local accents = "́̀"
local nondentals = "бвгжкпмшБВГЖКПМШ"
function export.tr(text, lang, sc)
-- make all word borders have a space
text = " " .. text .. " "
-- front vowels after another vowel are written with initial j
text = gsub(text, "(?)()", "%1j%2")
text = gsub(text, "(?)()", "%1J%2")
-- repeat to catch all instances
text = gsub(text, "(?)()", "%1j%2")
text = gsub(text, "(?)()", "%1J%2")
-- е, ё, ю, я at the beginning of a word are also written with initial j
text = gsub(text, " ()", " j%1")
text = gsub(text, " ()", " J%1")
-- я after non-dental consonants becomes ä
text = gsub(text, "()я", "%1ä")
text = gsub(text, "()Я", "%1Ä")
-- ё after non-dental consonants becomes œ
text = gsub(text, "()ё", "%1ö")
text = gsub(text, "()Ё", "%1Ö")
-- make Е, Ё, Ю, Я lowercase if preceding a non-capital letter
text = gsub(text, "()()", function(v, l)
return lower(v) .. l
end)
-- dental consonants before ь and front vowels are palatalized
for i, v in pairs(palatals) do
text = gsub(text, i .. "ь", v)
text = gsub(text, i .. "()", v .. "%1")
end
-- ъ and ь are omitted before a front vowel
text = gsub(text, "ъ()","j%1")
text = gsub(text, "Ъ()","J%1")
return trim(gsub(text, ".", letters))
end
return export