Module:xchc-translit

Revision as of 15:23, 26 November 2023 by Sware (talk | contribs)


local u = mw.ustring.char
local M = u(0x0304) -- COMBINING MACRON
local B = u(0x0306) -- COMBINING BREVE
local D = u(0x0308) -- COMBINING DIAERESIS
local A = u(0x0301) -- COMBINING ACUTE
local DA = u(0x030B) -- COMBINING DOUBLE ACUTE

local export = {}

local MorA = "[" .. M .. A .. "]" 

local tt_lepik = {
	["А"]='A', ["а"]='a',
	["Я"]='Ja', ["я"]='ja',
	
	["Б"]='B', ["б"]='b',
	["В"]='V', ["в"]='v',
	["Г"]='G', ["г"]='g',
	["Ғ"]='Gh', ["ғ"]='gh',
	
	["Д"]='D', ["д"]='d', ["З"]='Z', ["з"]='z', ["Ж"]='Ž', ["ж"]='ž',
	
	["Е(" .. M .. "?)" .. D]='Jo%1', ["е(" .. M .. "?)" .. D]='jo%1',
	["Е"]='Je', ["е"]='je',
	
	["Ы"]='I', ["ы"]='i',
	["И"]='Ji', ["и"]='ji',
	
	["К"]='K', ["к"]='k',
	["Л"]='L', ["л"]='l',
	["М"]='M', ["м"]='m',
	["Н"]='N', ["н"]='n',
	["Ӈ"]='Ng', ["ӈ"]='ng',
	
	["О" .. M .. B]='A' .. DA, ["о" .. M .. B]='a' .. DA,
	["О" .. B]='A' .. D, ["о" .. B]='a' .. D,
	["Е(" .. M .. "?)" .. D]='Jo%1', ["е(" .. M .. "?)" .. D]='jo%1',
	["О"]='O', ["о"]='o',
	
	["Ө" .. M]='O' .. DA, ["ө" .. M]='o' .. DA,
	["Ө"]='O' .. D, ["ө"]='o' .. D,
	
	["П"]='P', ["п"]='p',
	["Р"]='R', ["р"]='r',
	["С"]='S', ["с"]='s',
	["Т"]='T', ["т"]='t',
	
	["У"]='U', ["у"]='u',
	["Ю"]='Ju', ["ю"]='ju',
	
	["Ү" .. M]='U' .. DA, ["ү" .. M]='u' .. DA,
	["Ү"]='U' .. D, ["ү"]='u' .. D,
	
	["Ф"]='F', ["ф"]='f',
	
	["ХӀ"]='H', ["хӀ"]='h',
	["Х"]='Ch', ["х"]='ch',
	
	["Ц"]='C', ["ц"]='c',
	["Ч"]='Cs', ["ч"]='cs',
	["Ш"]='Š', ["ш"]='š',
	
	["Э" .. M .. B]='E' .. DA, ["э"]='e' .. DA,
	["Э" .. B]='E' .. D, ["э"]='e' .. D,
	["Э"]='E', ["э"]='e',
	
	["І"]='J', ["і"]='j',
	["Ь"]='Y', ["ь"]='y',
	["[Ъъ]"]="'",
	["([LNln])j([aeiouy])"]='%1y%2'
};

function export.tr(text, lang, sc)
	
	text = text:gsub("Й", "J"):gsub("й", "j")
	
	text = mw.ustring.toNFD(text)
	
	for pat, repl in pairs(tt_lepik) do
		text = mw.ustring.gsub(text, pat, repl)
	end
	
	text = mw.ustring.toNFD(text):gsub("([LNln])j([aeiouy])", "%1y%2")
								 :gsub(M,A)
								 :gsub(A .. D, DA):gsub(D .. A, DA)
	
	return mw.ustring.toNFC(text):gsub("([Dd])z","%1c"):gsub("([Dd])ž","%1z")
end

return export