Documentation for this module may be created at မော်ဂျူး:chm-translit/doc

local export = {}
 
local tab = {
	["А"]="A", ["Б"]="B", ["В"]="V", ["Г"]="G", ["Д"]="D", ["Е"]="E", ["Ё"]="Jo", ["Ж"]="Ž", ["З"]="Z", ["И"]="I", ["Й"]="J",
	["К"]="K", ["Л"]="L", ["М"]="M", ["Н"]="N", ["Ҥ"]="Ŋ", ["О"]="O", ["Ӧ"]="Ö", ["П"]="P", ["Р"]="R", ["С"]="S", ["Т"]="T",
	["У"]="U", ["Ӱ"]="Ü", ["Ф"]="F", ["Х"]="H", ["Ц"]="C", ["Ч"]="Č", ["Ш"]="Š", ["Щ"]="Ŝ", ["Ъ"]="", ["Ы"]="Y", ["Ь"]="",
	["Э"]="e", ["Ю"]="U", ["Я"]="A",
	['а']='a', ['б']='b', ['в']='v', ['г']='g', ['д']='d', ['е']='e', ['ё']='jo', ['ж']='ž', ['з']='z', ['и']='i', ['й']='j',
	['к']='k', ['л']='l', ['м']='m', ['н']='n', ['ҥ']='ŋ', ['о']='o', ['ӧ']='ö', ['п']='p', ['р']='r', ['с']='s', ['т']='t',
	['у']='u', ['ӱ']='ü', ['ф']='f',
	['х']='h', ['ц']='c', ['ч']='č', ['ш']='š', ['щ']='ŝ', ['ъ']='', ['ы']='y', ['ь']='', ['э']='e', ['ю']='u', ['я']='a',
	-- Hill (Western) Mari only, doesn't use Ҥ, ҥ
	["Ӓ"]="Ä", ["Ӹ"]="Ÿ", ['ӓ']='ä', ['ӹ']='ÿ', 
	
	-- Northwestern Mari only
	["Ө"]="Ou", ["Ӫ"]="Öü", ['ө']='ou', ['ӫ']='öü', 
	-- NOTE: non-standart transliteration, please suggest better variants at documentation before replacing
}

function export.tr(text, lang, sc)
	-- Ё needs converting if is decomposed
	text = text:gsub("ё","ё"):gsub("Ё","Ё")
 
    -- iotated vowels after a vowel or at the beginning of a word become j-
    text = mw.ustring.gsub(text, "([АӒОӨÖӪУӰЫӸЕЯЁЮИЕЪЬаӓоөöӫуӱыӹэяёюиеъь%A][\204\129\204\128]?)([еёюя])", "%1j%2")
    text = mw.ustring.gsub(text, "^([ЕЁЮЯ])", "J%1")
    text = mw.ustring.gsub(text, "^([еёюя])", "j%1")
    
    -- soft consonants
    text = mw.ustring.gsub(text, "([НЛнл])([еёияюь])", "%1Q%2")
    text = mw.ustring.gsub(text, "НQ", "Ń")
    text = mw.ustring.gsub(text, "нQ", "ń")
    text = mw.ustring.gsub(text, "ЛQ", "Ĺ")
    text = mw.ustring.gsub(text, "лQ", "ĺ")
 
	return (mw.ustring.gsub(text,'.',tab))
end
 
return export