Module:udi-translit

From Linguifex
Jump to navigation Jump to search

This module will transliterate Udi 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:udi-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 gsub = string.gsub
local u = require("Module:string utilities").char

local export = {}

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

local trigraphs = {
	['джъ'] = 'ǯ:',
	['джӏ'] = 'ǯ:',
	['чӏъ'] = 'č̣:',
	['Джъ'] = 'Ǯ:',
	['Джӏ'] = 'Ǯ:',
	['Чӏъ'] = 'Č̣:',
}
local digraphs = {
	['пӏ'] = 'ṗ',
	['тӏ'] = 'ṭ',
	['дз'] = 'ʒ',
	['цӏ'] = 'c̣',
	['дж'] = 'ǯ',
	['чӏ'] = 'č̣',
	['чъ'] = 'č:',
	['жъ'] = 'ž:',
	['жӏ'] = 'ž:',
	['шъ'] = 'š:',
	['шӏ'] = 'š:',
	['кӏ'] = 'ḳ',
	['гъ'] = 'ɣ',
	['къ'] = 'q̇',
	['хъ'] = 'q',
	['гь'] = 'h',
	['уь'] = 'ü',
	['оь'] = 'ö',
	['аь'] = 'ä',
	['иӏ'] = 'i̱',
	['иъ'] = 'i̱',
	['уӏ'] = 'u̱',
	['уъ'] = 'u̱',
	['еӏ'] = 'e̱',
	['еъ'] = 'e̱',
	['оӏ'] = 'o̱',
	['оъ'] = 'o̱',
	['аӏ'] = 'a̱',
	['аъ'] = 'a̱',
	['ыъ'] = 'ə̱',
	['Пӏ'] = 'Ṗ',
	['Тӏ'] = 'Ṭ',
	['Дз'] = 'Ʒ',
	['Цӏ'] = 'C̣',
	['Дж'] = 'Ǯ',
	['Чӏ'] = 'Č̣',
	['Чъ'] = 'Č:',
	['Жъ'] = 'Ž:',
	['Жӏ'] = 'Ž:',
	['Шъ'] = 'Š:',
	['Шӏ'] = 'Š:',
	['Кӏ'] = 'Ḳ',
	['Гъ'] = 'Ɣ',
	['Къ'] = 'Q̇',
	['Хъ'] = 'Q',
	['Гь'] = 'H',
	['Уь'] = 'Ü',
	['Оь'] = 'Ö',
	['Аь'] = 'Ä',
	['Иӏ'] = 'I̱',
	['Иъ'] = 'I̱',
	['Уӏ'] = 'U̱',
	['Уъ'] = 'U̱',
	['Еӏ'] = 'E̱',
	['Еъ'] = 'E̱',
	['Оӏ'] = 'O̱',
	['Оъ'] = 'O̱',
	['Аӏ'] = 'A̱',
	['Аъ'] = 'A̱',
	['Ыъ'] = 'Ə̱',
}

function export.tr(text, lang, sc)
	if sc ~= "Cyrl" then
		return nil
	end
	
	-- Convert capital to lowercase palochka. Lowercase is found in tables
	-- above.
	text = gsub(text, u(0x4C0), u(0x4CF))
	
	for trigraph, translit in pairs(trigraphs) do
		text = gsub(text, trigraph, translit)
	end
	
	for digraph, translit in pairs(digraphs) do
		text = gsub(text, digraph, translit)
	end
	
	text = gsub(text, ".[\128-\191]*", tt)
	
	return text
end

return export