Module:xchc-translit: Difference between revisions

From Linguifex
Jump to navigation Jump to search
No edit summary
No edit summary
 
(77 intermediate revisions by the same user not shown)
Line 1: Line 1:
local u = mw.ustring.char
local u = mw.ustring.char
local M = u(0x0304)
local M = u(0x0304) -- COMBINING MACRON
local B = u(0x0306)
local B = u(0x0306) -- COMBINING BREVE
local D = u(0x0308)
local D = u(0x0308) -- COMBINING DIAERESIS
local MB = M .. B
local A = u(0x0301) -- COMBINING ACUTE
local DA = u(0x030B) -- COMBINING DOUBLE ACUTE


local export = {}
local export = {}


local tt = { -- Unofficial transliteration loosely based on ISO 9
local MorA = "[" .. M .. A .. "]"  
["І"]='J', ["і"]='j',
 
["Э"]='E', ["э"]='e', ["Ĕ" .. M]='', ["ĕ" .. M]='ḗ', ["Ĕ"]='É', ["ĕ"]='é',
local tt_lepik = {
["О"]='O', ["о"]='o', ["Ŏ" .. M]='Ṓ', ["ŏ" .. M]='ṓ', ["Ŏ"]='Ó', ["ŏ"]='ó',
["Е" .. M .. D]='Jo' .. M, ["е" .. M .. D]='jo' .. M,
["Е" .. D]='Jo', ["е" .. D]='jo',
["А"]='A', ["а"]='a',
["Я"]='Ja', ["я"]='ja',
["Е" .. M .. D]='Jō', ["е" .. M .. D]='jō', ["Ё"]='Jo', ["ё"]='jo',
["А" .. M]='Ā', ["а" .. M]='ā', ["А"]='A', ["а"]='a',
["Б"]='B', ["б"]='b',
["Б"]='B', ["б"]='b',
["В"]='V', ["в"]='v',
["В"]='V', ["в"]='v',
["Г"]='G', ["г"]='g',
["Г"]='G', ["г"]='g',
["Ғ"]='Ǧ', ["ғ"]='ǧ',
["Ғ"]='Gh', ["ғ"]='gh',
["Д"]='D', ["д"]='d',
["Е" .. M]='', ["е" .. M]='', ["Е"]='Je', ["е"]='je',
["Д"]='D', ["д"]='d', ["З"]='Z', ["з"]='z', ["Ж"]='Ž', ["ж"]='ž',
["Ж"]='Ž', ["ж"]='ž',
["З"]='Z', ["з"]='z',  
["Ы"]='I', ["ы"]='i',
["Ӣ"]='Jī', ["ӣ"]='jī', ["И"]='Ji', ["и"]='ji',
["И"]='Ji', ["и"]='ji',
["К"]='K', ["к"]='k',
["К"]='K', ["к"]='k',
["Л"]='L', ["л"]='l',
["Л"]='L', ["л"]='l',
["М"]='M', ["м"]='m',
["М"]='M', ["м"]='m',
["Н"]='N', ["н"]='n',
["Н"]='N', ["н"]='n',
["Ӈ"]='Ŋ', ["ӈ"]='ŋ',
["Ӈ"]='Ng', ["ӈ"]='ng',
["О" .. M]='Ō', ["о" .. M]='ō', ["О"]='O', ["о"]='o',
["Ө" .. M]='Ȫ', ["ө" .. M]='ȫ', ["Ө"]='Ö', ["ө"]='ö',
["[ОO]" .. B]='A' .. D, ["[оo]" .. B]='a' .. D,
["О" .. M .. B]='A' .. DA, ["о" .. M .. B]='a' .. DA,
["О"]='O', ["о"]='o',
["Ө" .. M]='O' .. DA, ["ө" .. M]='o' .. DA,
["Ө"]='O' .. D, ["ө"]='o' .. D,
["П"]='P', ["п"]='p',
["П"]='P', ["п"]='p',
["Р"]='R', ["р"]='r',
["Р"]='R', ["р"]='r',
["С"]='S', ["с"]='s',
["С"]='S', ["с"]='s',
["Т"]='T', ["т"]='t',
["Т"]='T', ["т"]='t',
["Ӯ"]='Ū', ["ӯ"]='ū', ["У"]='U', ["у"]='u',
["Ү" .. M]='Ȳ', ["ү" .. M]='ȳ', ["Ү"]='Y', ["ү"]='y',
["У"]='U', ["у"]='u',
["Ю"]='Ju', ["ю"]='ju',
["Ү" .. M]='U' .. DA, ["ү" .. M]='u' .. DA,
["Ү"]='U' .. D, ["ү"]='u' .. D,
["Ф"]='F', ["ф"]='f',
["Ф"]='F', ["ф"]='f',
["ХӀ"]='H', ["хӀ"]='h', ["Х"]='X', ["х"]='x',
["Ц"]='Ts', ["ц"]='ts',
["ХӀ"]='H', ["хӀ"]='h',
["Ч"]='Č', ["ч"]='č',
["Х"]='Ch', ["х"]='ch',
["Ц"]='C', ["ц"]='c',
["Ч"]='Cs', ["ч"]='cs',
["Ш"]='Š', ["ш"]='š',
["Ш"]='Š', ["ш"]='š',
["Ы" .. M]='Ī', ["ы" .. M]='ī', ["Ы"]='I', ["ы"]='i',
["Ю" .. M]='Jū', ["ю" .. M]='jū', ["Ю"]='Ju', ["ю"]='ju',
["Я" .. M]='Jā', ["я" .. M]='jā', ["Я"]='Ja', ["я"]='ja',
["L[ьj]"] = "Ľ", ["l[ьj]"] = "ľ",
["[ЭE]" .. M .. B]='E' .. DA, ["[эe]" .. M .. B]='e' .. DA,
["N[ьj]"]='Ň', ["n[ьj]"]='ň',  
["Э" .. B]='E' .. D, ["э" .. B]='e' .. D,
["[ьЬ]"]="'", ["[Ъъ]"]='"',
["Э"]='E', ["э"]='e',
["L['j]"]='Ľ', ["l['j]"]='ľ', ["N'"]='Ň', ["n'"]='ň',
["І"]='J', ["і"]='j',
["Ь"]='Y', ["ь"]='y',
["Й"]='J', ["й"]='j',
["[Ъъ]"]="'",
["([LNln])j([aeiouy])"]='%1y%2'
};
};


function export.tr(text, lang, sc)
function export.tr(text, lang, sc)
for pat, repl in pairs(tt) do
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)
text = mw.ustring.gsub(text, pat, repl)
end
end
return text
text = mw.ustring.toNFD(text):gsub("([LNln])j([aeiouy])", "%1y%2")
:gsub("O" .. B, "A" .. D):gsub("o" .. B, "a" .. D)
:gsub(M,A)
:gsub(A .. D, DA):gsub(D .. A, DA)
return mw.ustring.toNFC(text):gsub("([Dd])z","%1c"):gsub("([Dd])ž","%1z")
end
end


return export
return export

Latest revision as of 16:02, 26 November 2023



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 = {
	["Е" .. M .. D]='Jo' .. M, ["е" .. M .. D]='jo' .. M,
	["Е" .. D]='Jo', ["е" .. D]='jo',
	
	["А"]='A', ["а"]='a',
	["Я"]='Ja', ["я"]='ja',
	
	["Б"]='B', ["б"]='b',
	["В"]='V', ["в"]='v',
	["Г"]='G', ["г"]='g',
	["Ғ"]='Gh', ["ғ"]='gh',
	
	["Д"]='D', ["д"]='d', ["З"]='Z', ["з"]='z', ["Ж"]='Ž', ["ж"]='ž',
	
	["Ы"]='I', ["ы"]='i',
	["И"]='Ji', ["и"]='ji',
	
	["К"]='K', ["к"]='k',
	["Л"]='L', ["л"]='l',
	["М"]='M', ["м"]='m',
	["Н"]='N', ["н"]='n',
	["Ӈ"]='Ng', ["ӈ"]='ng',
	
	["[ОO]" .. B]='A' .. D, ["[оo]" .. B]='a' .. D,
	["О" .. M .. B]='A' .. DA, ["о" .. M .. B]='a' .. DA,
	["О"]='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',
	["Ш"]='Š', ["ш"]='š',
	
	["[ЭE]" .. M .. B]='E' .. DA, ["[эe]" .. M .. B]='e' .. DA,
	["Э" .. B]='E' .. D, ["э" .. B]='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("O" .. B, "A" .. D):gsub("o" .. B, "a" .. D)
								 :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