Module:sel-sou-translit

From Linguifex
Revision as of 16:57, 19 February 2025 by wikt>Surjection (Protected "Module:sel-sou-translit": Highly visible template/module ([Edit=Allow only autoconfirmed users] (indefinite) [Move=Allow only autoconfirmed users] (indefinite)))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This module will transliterate Southern Selkup 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:sel-sou-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 export = {}

local u = mw.ustring.char

local macron = u(0x0304)
local acute = u(0x0300)

local tt = {
	["А"]='A', ["а"]='a',
	["Ӓ"]="’a", ["ӓ"]="’a",
	["Б"]='B', ["б"]='b',
	["В"]='W', ["в"]='w',
	["Г"]='G', ["г"]='g',
	["Ӷ"]='Ģ', ["ӷ"]='ģ',
	["Д"]='D', ["д"]='d',
	["Е"]='Je', ["е"]='je',
	["Ё"]="Jo", ["ё"]="jo",
	["Ж"]='Ž', ["ж"]='ž',
	["Җ"]='Ǯ', ["җ"]='ǯ',
	["З"]='Z', ["з"]='z',
	["И"]='I', ["и"]='i',
	["И̇"]="Ï", ["и̇"]="ї",
	["Й"]="J", ["й"]="j",
	["К"]='K', ["к"]='k',
	["Ӄ"]='Q', ["ӄ"]='q',
	["Л"]='L', ["л"]='l',
	["М"]='M', ["м"]='m',
	["Н"]='N', ["н"]='n',
	["Ӈ"]="Ŋ", ["ӈ"]="ŋ",
	["О"]='O', ["о"]='o',
	["Ӧ"]='Ö', ["ӧ"]='ö',
	["П"]='P', ["п"]='p', 
	["Р"]='R', ["р"]='r',
	["С"]='S', ["с"]='s',
	["Т"]='T', ["т"]='t',
	["У"]='U', ["у"]='u', 
	["Ӱ"]='Ü', ["ӱ"]='ü', 
	["Ӯ"]="Ū", ["ӯ"]="ū",
	["Ф"]='F', ["ф"]='f',
	["Х"]='X', ["х"]='x',
	["Ҳ"]="X", ["ҳ"]="x",
	["Ц"]='C', ["ц"]='c',
	["Ч"]='Č', ["ч"]='č',
	["Ш"]='Š', ["ш"]='š',
	["Щ"]="Šč", ["щ"]="šč",
	["Ы"]="Y", ["ы"]="y",
	["Ъ"]="", ["ъ"]="",
	["Ь"]="’", ["ь"]="’",
	["Э"]="E", ["э"]="e",
	["Ю"]="Ju", ["ю"]="ju",
	["Я"]="Ja", ["я"]="ja",
}

local vowel = "аӓеёиӣоӧуӱӯыэюяАӒЕЁИӢОӦУӰӮЫЭЮЯ"

function export.tr(text, lang, sc)
	
	-- initial j + vowels
	text = mw.ustring.gsub(text, "^" .. "я" .. macron, "jā")
	text = mw.ustring.gsub(text, "^" .. "е" .. macron, "je")
	text = mw.ustring.gsub(text, "^" .. "ӣ", "jī")
	text = mw.ustring.gsub(text, "^" .. "ю" .. macron, "jū")
	text = mw.ustring.gsub(text, "^" .. "Я" .. macron, "Jā")
	text = mw.ustring.gsub(text, "^" .. "Е" .. macron, "Jē")
	text = mw.ustring.gsub(text, "^" .. "Ӣ", "Jī")
	text = mw.ustring.gsub(text, "^" .. "Ю" .. macron, "Jū")

	text = mw.ustring.gsub(text, " " .. "я" .. macron, "jā")
	text = mw.ustring.gsub(text, " " .. "е" .. macron, "je")
	text = mw.ustring.gsub(text, " " .. "ӣ", "jī")
	text = mw.ustring.gsub(text, " " .. "ю" .. macron, "jū")
	text = mw.ustring.gsub(text, " " .. "Я" .. macron, "Jā")
	text = mw.ustring.gsub(text, " " .. "Е" .. macron, "Jē")
	text = mw.ustring.gsub(text, " " .. "Ӣ", "Jī")
	text = mw.ustring.gsub(text, " " .. "Ю" .. macron, "Jū")

	return (mw.ustring.gsub(text, '.', tt))
end

return export