Module:rut-translit

From Linguifex
Jump to navigation Jump to search

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

local export = {}

local tt = {
	["б"]="b", ["п"]="p", ["ф"]="f", ["д"]="d", ["т"]="t", ["ц"]="c",
	["з"]="z", ["с"]="s", ["ч"]="č", ["ж"]="ž", ["ш"]="š", ["г"]="g",
	["к"]="k", ["х"]="ꭓ", ["ъ"]="ʔ", ["м"]="m", ["н"]="n", ["р"]="r",
	["л"]="l", ["в"]="v", ["й"]="j", ["ю"]="ju", ["я"]="ja", ["ё"]="jo",
	["и"]="i", ["е"]="je", ["э"]="e", ["а"]="a", ["ы"]="ɨ", ["о"]="o", ["у"]="u",

	["Б"]="B", ["П"]="P", ["Ф"]="F", ["Д"]="D", ["Т"]="T", ["Ц"]="C",
	["З"]="Z", ["С"]="S", ["Ч"]="Č", ["Ж"]="Ž", ["Ш"]="Š", ["Г"]="G",
	["К"]="K", ["Х"]="Ꭓ", ["Ъ"]="ʔ", ["М"]="M", ["Н"]="N", ["Р"]="R",
	["Л"]="L", ["В"]="V", ["Й"]="J", ["Ю"]="Ju", ["Я"]="Ja", ["Ё"]="Jo",
	["И"]="I", ["Е"]="Je", ["Э"]="E", ["А"]="A", ["Ы"]="Ɨ", ["О"]="O", ["U"]="U",
}

local roundings = {
	'([тцчкТЦЧК]ӏ)в',
	'([кхгКХГ]ъ)в',
	'([цсшчгкхЦСШЧГКХ])в',
	'([дД]ж)в', '([хХ]ь)в',
}

local digraphs = {
	['пӏ'] = 'ṗ', ['Пӏ'] = 'Ṗ',
	['тӏ'] = 'ṭ', ['Тӏ'] = 'Ṭ',
	['дз'] = 'ʒ', ['Дз'] = 'Ʒ',
	['цӏ'] = 'c̣', ['Цӏ'] = 'C̣',
	['дж'] = 'ǯ', ['Дж'] = 'Ǯ',
	['чӏ'] = 'č̣', ['Чӏ'] = 'Č̣',
	['кӏ'] = 'ḳ', ['Кӏ'] = 'Ḳ',
	['гӏ'] = 'ɣ', ['Гӏ'] = 'Ɣ',
	['хь'] = 'x', ['Хь'] = 'X',
	['хӏ'] = 'ħ', ['Хӏ'] = 'Ħ',
	['къ'] = 'q:', ['Къ'] = 'Q:',
	['хъ'] = 'q', ['Хъ'] = 'Q',
	['кь'] = 'q̇', ['Кь'] = 'Q̇',
	['гъ'] = 'ʁ', ['Гъ'] = 'ʁ',
	['гь'] = 'h', ['Гь'] = 'H',
	['аь'] = 'ä', ['Аь'] = 'Ä',
	['уь'] = 'ü', ['Уь'] = 'Ü',
	['([ауыАУЫ])ӏ'] = '%1ˤ',
}

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))

	-- Non-initial е is not je.
	text = gsub(text, "([Ё-ӏ])е", "%1e")

	for _, rounding in ipairs(roundings) do
		text = gsub(text, rounding, "%1ʷ")
	end

	for digraph, translit in pairs(digraphs) do
		text = gsub(text, digraph, translit)
	end

	text = gsub(text, "[Ё-ӏ]", tt)

	return text
end

return export