ข้ามไปเนื้อหา

มอดูล:mdf-translit

จาก วิกิพจนานุกรม พจนานุกรมเสรี
local export = {}

local tab = {
	["А"]="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',
}

function export.tr(text, lang, sc)

    -- Ё needs converting if is decomposed
    text = text:gsub("ё","ё"):gsub("Ё","Ё")

    -- е after a vowel or at the beginning of a word becomes je
    text = mw.ustring.gsub(text, "([АОУЫЭЯЁЮИЕЬаоуыэяёюиеь%A][́̀]?)е","%1je")
    text = mw.ustring.gsub(text, "^Е","Je")
    text = mw.ustring.gsub(text, "^е","je")
    text = mw.ustring.gsub(text, "([^Ѐ-ӿ])Е","%1Je")
    text = mw.ustring.gsub(text, "([^Ѐ-ӿ])е","%1je")
    
    -- и after a vowel becomes ji
    text = mw.ustring.gsub(text, "([АОУЫЭЯЁЮИЕЬаоуыэяёюие][́̀]?)и","%1ji")

    -- ю after a vowel or at the beginning of a word becomes ju
    text = mw.ustring.gsub(text, "([АОУЫЭЯЁЮИЕЬаоуыэяёюиеь%A][́̀]?)ю","%1ju")
    text = mw.ustring.gsub(text, "^Ю","Ju")
	text = mw.ustring.gsub(text, "^ю","ju")
	text = mw.ustring.gsub(text, "([^Ѐ-ӿ])Ю","%1Ju")
	text = mw.ustring.gsub(text, "([^Ѐ-ӿ])ю","%1ju")

    -- я after a vowel or at the beginning of a word becomes ja
    text = mw.ustring.gsub(text, "([АОУЫЭЯЁЮИЕЬаоуыэяёюиеь%A][́̀]?)я","%1ja")
    text = mw.ustring.gsub(text, "^Я","Ja")
	text = mw.ustring.gsub(text, "^я","ja")
	text = mw.ustring.gsub(text, "([^Ѐ-ӿ])Я","%1Ja")
	text = mw.ustring.gsub(text, "([^Ѐ-ӿ])я","%1ja")

    -- ё after a vowel or at the beginning of a word becomes jo
    text = mw.ustring.gsub(text, "([АОУЫЭЯЁЮИЕЬаоуыэяёюиеь%A][́̀]?)ё","%1jo")
    text = mw.ustring.gsub(text, "^Ё","Jo")
	text = mw.ustring.gsub(text, "^ё","jo")
	text = mw.ustring.gsub(text, "([^Ѐ-ӿ])Ё","%1Jo")
	text = mw.ustring.gsub(text, "([^Ѐ-ӿ])ё","%1jo")

    -- palatalization
	text = mw.ustring.gsub(text, "дь","ď")
    text = mw.ustring.gsub(text, "Дь","Ď")
	text = mw.ustring.gsub(text, "д([еёиюяЕЁИЮЯ])","ď%1")
    text = mw.ustring.gsub(text, "Д([еёиюяЕЁИЮЯ])","Ď%1")
	text = mw.ustring.gsub(text, "зь","ź")
    text = mw.ustring.gsub(text, "Зь","Ź")
	text = mw.ustring.gsub(text, "з([еёиюя])","ź%1")
    text = mw.ustring.gsub(text, "З([еёиюяЕЁИЮЯ])","Ź%1")
	text = mw.ustring.gsub(text, "ль","ľ")
    text = mw.ustring.gsub(text, "Ль","Ľ")
	text = mw.ustring.gsub(text, "л([еёиюя])","ľ%1")
    text = mw.ustring.gsub(text, "Л([еёиюяЕЁИЮЯ])","Ľ%1")
	text = mw.ustring.gsub(text, "нь","ń")
    text = mw.ustring.gsub(text, "Нь","Ń")
	text = mw.ustring.gsub(text, "н([еёиюя])","ń%1")
    text = mw.ustring.gsub(text, "Н([еёиюяЕЁИЮЯ])","Ń%1")
	text = mw.ustring.gsub(text, "рь","ŕ")
    text = mw.ustring.gsub(text, "Рь","Ŕ")
	text = mw.ustring.gsub(text, "р([еёиюя])","ŕ%1")
    text = mw.ustring.gsub(text, "Р([еёиюяЕЁИЮЯ])","Ŕ%1")
	text = mw.ustring.gsub(text, "сь","ś")
    text = mw.ustring.gsub(text, "Сь","Ś")
	text = mw.ustring.gsub(text, "с([еёиюя])","ś%1")
    text = mw.ustring.gsub(text, "С([еёиюяЕЁИЮЯ])","Ś%1")
	text = mw.ustring.gsub(text, "ть","ť")
    text = mw.ustring.gsub(text, "Ть","Ť")
	text = mw.ustring.gsub(text, "т([еёиюя])","ť%1")
    text = mw.ustring.gsub(text, "Т([еёиюяЕЁИЮЯ])","Ť%1")
	text = mw.ustring.gsub(text, "ць","ć")
    text = mw.ustring.gsub(text, "Ць","Ć")
	text = mw.ustring.gsub(text, "ц([еёиюя])","ć%1")
    text = mw.ustring.gsub(text, "Ц([еёиюяЕЁИЮЯ])","Ć%1")
	text = mw.ustring.gsub(text, "([бвгжкпмшБВГЖКПМШ])я", "%1æ")
	text = mw.ustring.gsub(text, "([бвгжкпмшБВГЖКПМШ])ё", "%1œ")

    -- ъ and ь before a vowel disappears
	text = mw.ustring.gsub(text, "ъ([еёиюяЕЁИЮЯ])","j%1")
	text = mw.ustring.gsub(text, "Ъ([еёиюяЕЁИЮЯ])","J%1")
        
    return (mw.ustring.gsub(text,'.',tab))
end

return export