Module:kjj-translit

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

This module will transliterate Khinalug language text. 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:kjj-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 u = require("Module:string/char")

local export = {}

local tt = {
	["б"]="b", ["п"]="p", ["в"]="w", ["ф"]="f",
	["д"]="d", ["т"]="t", ["ц"]="c", ["з"]="z", ["с"]="s", ["ч"]="č", ["ж"]="ž", ["ш"]="š",
	["г"]="g", ["к"]="k", ["х"]="χかい", ["ъ"]="ʔ", ["м"]="m", ["н"]="n", ["р"]="r", ["л"]="l",
	["й"]="j", ["и"]="i", ["е"]="e", ["э"]="e", ["а"]="a", ["о"]="o", ["у"]="u", ["ы"]="ɨ", 
	["Б"]="B", ["П"]="P", ["В"]="W", ["Ф"]="F",
	["Д"]="D", ["Т"]="T", ["Ц"]="C", ["З"]="Z", ["С"]="S", ["Ч"]="Č", ["Ж"]="Ž", ["Ш"]="Š",
	["Г"]="G", ["К"]="K", ["Х"]="Χかい", ["Ъ"]="ʔ", ["М"]="M", ["Н"]="N", ["Р"]="R", ["Л"]="L",
	["Й"]="J", ["И"]="I", ["Е"]="E", ["Э"]="E", ["А"]="A", ["О"]="O", ["У"]="U", ["Ы"]="Ɨ"};

local tetraTrigraphs = {
	['къкъ'] = 'qː',
	['кхь'] = 'kx',
	['Къкъ'] = 'Qː',
	['Кхь'] = 'Kx',
}

local digraphs = {
	['пп'] = 'pː',
	['пӏ'] = 'ṗ',
	['вв'] = 'wː',
	['тт'] = 'tː',
	['тӏ'] = 'ṭ',
	['цц'] = 'cː',
	['цӏ'] = 'c̣',
	['дж'] = 'ǯ',
	['чч'] = 'čː',
	['чӏ'] = 'č̣',
	['кк'] = 'kː',
	['кӏ'] = 'ḳ',
	['гг'] = 'ɣ',
	['хь'] = 'x',
	['къ'] = 'qː',
	['хъ'] = 'q',
	['кь'] = 'q̇',
	['гъ'] = 'ʁ',
	['гӏ'] = 'ʕ',
	['хӏ'] = 'ħ',
	['гь'] = 'h',
	['уь'] = 'ü',
	['оь'] = 'ö',
	['аь'] = 'ä',
	['Пп'] = 'Pː',
	['Пӏ'] = 'Ṗ',
	['Вв'] = 'Wː',
	['Тт'] = 'Tː',
	['Тӏ'] = 'Ṭ',
	['Цц'] = 'Cː',
	['Цӏ'] = 'C̣',
	['Дж'] = 'Ǯ',
	['Чч'] = 'Čː',
	['Чӏ'] = 'Č̣',
	['Кк'] = 'Kː',
	['Кӏ'] = 'Ḳ',
	['Гг'] = 'Ɣ',
	['Хь'] = 'X',
	['Къ'] = 'Qː',
	['Хъ'] = 'Q',
	['Кь'] = 'Q̇',
	['Гъ'] = 'ʁ',
	['Гӏ'] = 'ʕ',
	['Хӏ'] = 'Ħ',
	['Гь'] = 'H',
	['Уь'] = 'Ü',
	['Оь'] = 'Ö',
	['Аь'] = 'Ä',
}

function export.tr(text, lang, sc)
	local str_gsub = string.gsub
	local UTF8char = '[%z\1-\127\194-\244][\128-\191]*'
	
	-- Convert uppercase palochka to lowercase. Lowercase is found in tables
	-- above.
	text = str_gsub(text, u(0x4C0), u(0x4CF))
	
	for grapheme, replacement in pairs(tetraTrigraphs) do
		text = str_gsub(text, grapheme, replacement)
	end
	
	for digraph, replacement in pairs(digraphs) do
		text = str_gsub(text, digraph, replacement)
	end
	
	text = str_gsub(text, UTF8char, tt)
	
	return text
end

return export