Module:kv-translit

From Wiktionary, the free dictionary
Jump to navigation Jump to search

This module will transliterate Komi-Zyrian language text per WT:KPV TR. It is also used to transliterate Komi-Permyak, Komi-Zyrian, and Komi-Yazva. 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:kv-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.

It will also transliterate koi.


local export = {}

local tab = {
	["А"]="A", ["Б"]="B", ["В"]="V", ["Г"]="G", ["Д"]="D", ["Е"]="E", ["Ё"]="O", ["Ж"]="Ž", ["З"]="Z", ["И"]="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', ['ж']='ž', ['з']='z', ['и']='i', ['і']='i', ['й']='j',
	['к']='k', ['л']='l', ['м']='m', ['н']='n', ['о']='o', ['ӧ']='ö', ['п']='p', ['р']='r', ['с']='s', ['т']='t', ['у']='u', ['ф']='f',
	['х']='x', ['ц']='c', ['ч']='ć', ['ш']='š', ['щ']='šč', ['ъ']='', ['ы']='y', ['ь']='', ['э']='e', ['ю']='u', ['я']='a',	['Ө']='Å', 
	['ө']='å', ['Ӱ']='Ü', ['ӱ']='ü',
}

function export.tr(text, lang, sc)
	local language = lang
    -- Ё needs converting if is decomposed
    text = text:gsub("ё","ё"):gsub("Ё","Ё")
    
    -- тш
    text = mw.ustring.gsub(text, "Тш", "Č")
    text = mw.ustring.gsub(text, "тш", "č")
    
    -- soft consonants
    text = mw.ustring.gsub(text, "([Дд])з", "%1зQ")
    text = mw.ustring.gsub(text, "([ДЗЛНСТдзлнст])([еёияюь])", "%1Q%2")
    -- geminates
    text = mw.ustring.gsub(text, "([ДЗЛНСТдзлнст])([ДЗЛНСТдзлнст])([еёияюь])", "%1Q%2Q%3")
    if lang ~= "kpv" 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е")
    text = mw.ustring.gsub(text, "^Ё", "Jё")
    text = mw.ustring.gsub(text, "^Ю", "Jю")
    text = mw.ustring.gsub(text, "^Я", "jя")
    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