Jump to content

Module:udm-translit

From Wiktionary, the free dictionary

This module will transliterate Udmurt language text per WT:UDM 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:udm-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", ["Ё"]="O", ["Ж"]="Ž", ["Ӝ"]="Dž", ["З"]="Z", ["Ӟ"]="Dź", ["И"]="I", ["Ӥ"]="I", ["Й"]="J",
	["К"]="K", ["Л"]="L", ["М"]="M", ["Н"]="N", ["О"]="O", ["Ӧ"]="Ö", ["П"]="P", ["Р"]="R", ["С"]="S", ["Т"]="T", ["У"]="U", ["Ф"]="F",
	["Х"]="X", ["Ц"]="C", ["Ч"]="Ć", ["Ӵ"]="Č", ["Ш"]="Š", ["Щ"]="Šč", ["Ъ"]="", ["Ы"]="Y", ["Ь"]="", ["Э"]="E", ["Ю"]="U", ["Я"]="A",
	['а']='a', ['б']='b', ['в']='v', ['г']='g', ['д']='d', ['е']='e', ['ё']='o', ['ж']='ž', ['ӝ']='dž', ['з']='z', ['ӟ']='dź', ['и']='i', ['ӥ']='i', ['й']='j',
	['к']='k', ['л']='l', ['м']='m', ['н']='n', ['о']='o', ['ӧ']='ö', ['п']='p', ['р']='r', ['с']='s', ['т']='t', ['у']='u', ['ф']='f',
	['х']='x', ['ц']='c', ['ч']='ć', ['ӵ']='č', ['ш']='š', ['щ']='šč', ['ъ']='', ['ы']='y', ['ь']='', ['э']='e', ['ю']='u', ['я']='a', 
	-- Beserman
	['Ө']='Å', ['ө']='å', ['Ў']='W', ['ў']='w',
}

function export.tr(text, lang, sc)
	local language = lang
    -- Ё needs converting if is decomposed
    text = text:gsub("ё","ё"):gsub("Ё","Ё")
    
    -- soft consonants
    text = mw.ustring.gsub(text, "([ДЗЛНСТдзлнст])([еёияюь])", "%1Q%2")
    if lang ~= "udm" then 
    	text = mw.ustring.gsub(text, "([БВГЖКМПРФХЦЧШЩбвгжкмпрфхцчшщ])([ёяюь])", "%1Q%2") 
    end

    -- soft 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")
    
    -- palatalisation
    text = mw.ustring.gsub(text, "ДQ", "Ď")
    text = mw.ustring.gsub(text, "дQ", "ď")
    text = mw.ustring.gsub(text, "ЗQ", "Ź")
    text = mw.ustring.gsub(text, "зQ", "ź")
    text = mw.ustring.gsub(text, "ЛQ", "Ľ")
    text = mw.ustring.gsub(text, "лQ", "ľ")
    text = mw.ustring.gsub(text, "НQ", "Ń")
    text = mw.ustring.gsub(text, "нQ", "ń")
    text = mw.ustring.gsub(text, "СQ", "Ś")
    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