This module will transliterate text in one of the Mari languages. It is also used to transliterate Eastern Mari and Western Mari. 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:chm-translit/testcases.

Functions

tr(text, lang, sc)
Transliterates a given piece of text written in the script specified by the code sc, and language specified by the code lang.
When the transliteration fails, returns nil.

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