This module will transliterate Erzya language text per WT:MYV TR.
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:myv-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 gsub = mw.ustring.gsub
local lower = mw.ustring.lower
local trim = mw.text.trim
-- apply gsub() repeatedly until no change
local function gsub_repeatedly(term, foo, bar)
while true do
local new_term = gsub(term, foo, bar)
if new_term == term then
return term
end
term = new_term
end
end
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", ="Č", ="Š", ="Šč", ="", ="Ï", ="", ="Ë", ="U", ="A",
="Ä", ="E", ="Ŋ", ="I", ="Kv",
="a", ="b", ="v", ="g", ="d", ="e", ="o", ="ž", ="z", ="i", ="j",
="k", ="l", ="m", ="n", ="o", ="p", ="r", ="s", ="t", ="u", ="f",
="h", ="c", ="č", ="š", ="šč", ="", ="", ="ï", ="ë", ="u", ="a",
="ä", ="e", ="ŋ", ="i", ="kv"
}
local palatals = {
="Ď", = "Ź", = "Ľ", = "Ń", = "Ŕ", = "Ś", = "Ť", = "Ć",
="ď", = "ź", = "ľ", = "ń", = "ŕ", = "ś", = "ť", = "ć",
}
local vowels = "АОУЫЭЯЁЮИЕЪЬІаоуыэяёюиеъьі"
local back = "ЁЮЯёюя"
local accents = "́̀"
local nonpalatals = "бвгжкпмшБВГЖКПМШ"
function export.tr(text, lang, sc)
-- make all word borders have a space
text = " " .. text .. " "
-- only the last consonant in the sequence is palatalized
text = mw.ustring.gsub(text, "()ь(+)", "%1%2")
-- an experimental feature --
text = mw.ustring.gsub(text, "()ь(*)", "%1%2")
-- е, ё, ю, я after another vowel are written with initial j
text = gsub_repeatedly(text, "(?)()", "%1j%2")
text = gsub_repeatedly(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 – are also written with initial j
text = gsub(text, "-()", "-j%1")
text = gsub(text, "-()", "-J%1")
-- э at the beginning of the word is written as e
text = mw.ustring.gsub(text, "({}\"“”«»„“%-])э", "%1e")
text = mw.ustring.gsub(text, "({}\"“”«»„“%-])Э", "%1E")
-- я after non-palatal consonants becomes ä
text = gsub(text, "()я", "%1ä")
text = gsub(text, "()Я", "%1Ä")
-- ё after non-palatal 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)
-- consonants before ь and back (central) vowels are palatalized
for i, v in pairs(palatals) do
text = gsub(text, i .. "ь", v)
text = gsub(text, i .. "()", v .. "%1")
end
return trim(gsub(text, ".", letters))
end
return export