Documentation for this module may be created at Module:mn-translit/doc

local export = {}

local trfunc = {}

local tt_Cyrl = {
	["Щ"]="Šč", ['щ']='šč', ["Ы"]="Y", ['ы']='y', ["Э"]="E" ,['э']='e' , ["Я"]="Ja",['я']='ja', ["У"]="U",['у']='u', ["С"]="S" ,['с']='s',
	["Ч"]="Č" , ['ч']='č' , ["Х"]="H", ['х']='h', ["Ж"]="Ž" ,['ж']='ž' , ["Д"]="D" ,['д']='d' , ["В"]="V",['в']='v', ["А"]="A" ,['а']='a',
	["М"]="M" , ['м']='m' , ["О"]="O", ['о']='o', ["И"]="I" ,['и']='i' , ["К"]="K" ,['к']='k' , ["Ш"]="Š",['ш']='š', ["Ъ"]="ʺ" ,['ъ']='ʺ',
	["Ё"]="Jo", ['ё']='jo', ["Ь"]="ʹ", ['ь']='ʹ', ["Ю"]="Ju",['ю']='ju', ["Т"]="T" ,['т']='t' , ["Р"]="R",['р']='r', ["Ц"]="Ts",['ц']='ts',
	["Ф"]="F" , ['ф']='f' , ["З"]="Z", ['з']='z', ["Е"]="E" ,['е']='e' , ["Г"]="G" ,['г']='g' , ["Б"]="B",['б']='b', ["Н"]="N" ,['н']='n',
	["П"]="P" , ['п']='p' , ["Й"]="J", ['й']='j', ["Л"]="L" ,['л']='l' , ["Ү"]="Ü" ,['ү']='ü' , ["Ө"]="Ö",['ө']='ö'
}

function trfunc.Cyrl(text)
	text = mw.ustring.gsub(text, "([АОУЫЕЯЁЮИЕЪЬаоуыэяёюиеъь%A][\204\129\204\128]?)([Ее])",
		function (a, e)
			return a .. (e == 'е' and 'je' or 'Je')
		end):gsub("^Е",'Je'):gsub("^е",'je')
	return (mw.ustring.gsub(text, '.', tt_Cyrl))
end

function trfunc.Mong(text)
	-- TODO
	return nil
end

function export.tr(text, lang, sc)
	if not sc then
		local m_utilities = require('Module:utilities')
		sc = m_utilities.detect_script(text, require("Module:languages").getLanguageByCode("mn"))
	end
	
	if trfunc[sc] then
		return trfunc[sc](text)
	end
end

return export