Jump to content

Module:udi-translit

From Wiktionary, the free dictionary

This module will transliterate Udi language text per WT:UDI 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: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ʲ",
	};

local trigraphs = {
	['джъ'] = 'ǯ:',
	['джӏ'] = 'ǯ:',
	['чӏъ'] = 'č̣:',
}
local digraphs = {
	['пӏ'] = 'ṗ',
	['тӏ'] = 'ṭ',
	['дз'] = 'ʒ',
	['цӏ'] = '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