Module:lez-translit

Definition from Wiktionary, the free dictionary
Jump to: navigation, search

This module will transliterate Lezgi language text per WT:LEZ 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:lez-translit/testcases.

Functions[edit]

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 tt = {
	["б"]="b", ["п"]="p", ["ф"]="f", ["в"]="v", ["м"]="m",
	["д"]="d", ["т"]="t", ["й"]="j", ["н"]="n", ["з"]="z", ["ц"]="c",
	["с"]="s", ["ж"]="ž", ["ш"]="š", ["щ"]="šč", 
	["л"]="l", ["ч"]="č", ["р"]="r", ["г"]="g", ["к"]="k", ["х"]="χ", 
	["ъ"]="ʾ", ["а"]="a", ["е"]="e", ["ы"]="y", ["и"]="i", ["о"]="o", ["у"]="u", 
	["ё"]="ë", ["ь"]="’", ["э"]="è", ["ю"]="ju", ["я"]="ä",
	["Б"]="B", ["П"]="P", ["Ф"]="F", ["В"]="V", ["М"]="M",
	["Д"]="D", ["Т"]="T", ["Й"]="J", ["Н"]="N", ["З"]="Z", ["Ц"]="C",
	["С"]="S", ["Ж"]="Ž", ["Ш"]="Š", ["Щ"]="Šč", 
	["Л"]="L", ["Ч"]="Č", ["Р"]="R", ["Г"]="G", ["К"]="K", ["Х"]="Χ", 
	["Ъ"]="ʾ", ["А"]="A", ["Е"]="E", ["Ы"]="Y", ["И"]="I", ["О"]="O", ["У"]="U", 
	["Ё"]="Ë", ["Ь"]="’", ["Э"]="È", ["Ю"]="Ju", ["Я"]="Ä"};

local trigraphs = {
	['хъв'] = 'q°',
	['Хъв'] = 'Q°',
	['къв'] = 'q̄°',
	['Къв'] = 'Q̄°',
	['кьв'] = 'q̇°',
	['Кьв'] = 'Q̇°',
	['гъв'] = 'ġ°',
	['Гъв'] = 'Ġ°',
	['ттв'] = 't̄°',
	['Ттв'] = 't̄°',
	['ццв'] = 'c̄°',
	['Ццв'] = 'C̄°',
	['ккв'] = 'k̄°',
	['Ккв'] = 'K̄°',
	['тӏв'] = 'ṭ°',
	['Тӏв'] = 'Ṭ°',
	['цӏв'] = 'c̣°',
	['Цӏв'] = 'C̣°',
	['кӏв'] = 'ḳ°',
	['Кӏв'] = 'Ḳ°',
}

local digraphs = {
	['тв'] = 't°',
	['Тв'] = 'T°',
	['зв'] = 'z°',
	['Зв'] = 'Z°',
	['хв'] = 'χ°',
	['Хв'] = 'Χ°',
	['цв'] = 'c°',
	['Цв'] = 'C°',
	['св'] = 's°',
	['Св'] = 'S°',
	['пп'] = 'p̄',
	['пӏ'] = 'ṗ',
	['тт'] = 't̄', 
	['Пп'] = 'P̄',
	['Пӏ'] = 'Ṗ',
	['Тт'] = 'T̄',
	['цӏ'] = 'c̣',
	['цц'] = 'c̄',
	['тӏ'] = 'ṭ',
	['чч'] = 'č̄',
	['чӏ'] = 'č̣',
	['кь'] = 'q̇',
	['кк'] = 'k̄',
	['кӏ'] = 'ḳ',
	['хъ'] = 'q',
	['къ'] = 'q̄',
	['гъ'] = 'ġ',
	['гь'] = 'h',
	['Цӏ'] = 'C̣',
	['Цц'] = 'C̄',
	['Тӏ'] = 'Ṭ',
	['Чч'] = 'Č̄',
	['Чӏ'] = 'Č̣',
	['Кь'] = 'Q̇',
	['Кк'] = 'K̄',
	['Кӏ'] = 'Ḳ',
	['Хъ'] = 'Q',
	['Къ'] = 'Q̄',
	['Гъ'] = 'Ġ',
	['Гь'] = 'H',
	['уь'] = 'ü',
	['Уь'] = 'Ü',
	['хь'] = 'x',
	['Хь'] = 'X',
	['гв'] = 'g°',
	['Гв'] = 'G°',
	['кв'] = 'k°',
	['Кв'] = 'K°',
}

function export.tr(text, lang, sc)
	for digraph, replacement in pairs(digraphs) do
		text = mw.ustring.gsub(text, digraph, replacement)
	end
	
	for trigraph, replacement in pairs(trigraphs) do
		text = mw.ustring.gsub(text, trigraph, replacement)
	end
	
	text = mw.ustring.gsub(text, '.', tt)
	
	return text
end

return export