Module:sjd-translit

From Linguifex
Revision as of 23:28, 9 January 2026 by wikt>Merrahtar
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This module will transliterate Kildin Sami 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:sjd-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 tt = {
	["А"]='A', ["а"]='a',
	["Ӓ"]="’a", ["ӓ"]="’a",
	["Б"]='B', ["б"]='b',
	["В"]='V', ["в"]='v',
	["Г"]='G', ["г"]='g',
	["Д"]='D', ["д"]='d',
	["Е"]='Je', ["е"]='je',
	["Ё"]="Jo", ["ё"]="jo",
	["Ж"]='Ž', ["ж"]='ž',
	["З"]='Z', ["з"]='z',
	["Һ"]="H", ["һ"]="h", ["ʼ"]="h",
	["И"]='I', ["и"]='i',
	["Ӣ"]="Ī", ["ӣ"]="ī",
	["Й"]="J", ["й"]="j",
	["Ј"]="J̥", ["ј"]="j̥", ["Ҋ"]="J̥", ["ҋ"]="j̥",
	["К"]='K', ["к"]='k',
	["Л"]='L', ["л"]='l',
	["Ӆ"]='L̥', ["ӆ"]='l̥',
	["М"]='M', ["м"]='m',
	["Ӎ"]="M̥", ["ӎ"]="m̥",
	["Н"]='N', ["н"]='n',
	["Ӊ"]="N̥", ["ӊ"]="n̥",
	["Ӈ"]="Ŋ", ["ӈ"]="ŋ",
	["О"]='O', ["о"]='o',
	["П"]='P', ["п"]='p', 
	["Р"]='R', ["р"]='r',
	["Ҏ"]="R̥", ["ҏ"]="r̥",
	["С"]='S', ["с"]='s',
	["Т"]='T', ["т"]='t',
	["У"]='U', ["у"]='u', 
	["Ӯ"]="Ū", ["ӯ"]="ū",
	["Ф"]='F', ["ф"]='f',
	["Х"]='X', ["х"]='x',
	["Ц"]='C', ["ц"]='c',
	["Ч"]='Č', ["ч"]='č',
	["Ш"]='Š', ["ш"]='š',
	["Щ"]="Šč", ["щ"]="šč",
	["Ы"]="Y", ["ы"]="y",
	["Ъ"]="", ["ъ"]="",
	["Ь"]="’", ["ь"]="’", ["Ҍ"]= "’", ["ҍ"]="’",
	["Э"]="E", ["э"]="e",
	["Ӭ"]="’E", ["ӭ"]="’e",
	["Ю"]="Ju", ["ю"]="ju",
	["Я"]="Ja", ["я"]="ja",
}

local vowel = "аӓеёиӣоуӯыэӭюяАӒЕЁИӢОУӮЫЭӬЮЯ"
local consonant = "БбВвГгДдЖжЗзКкЛлӅӆМмӍӎНнӉӊӇӈПпРрҎҏСсТтХхЦцЧчШшЩщ"

function export.tr(text, lang, sc)
	-- initial palatal n + long vowel
	text = mw.ustring.gsub(text, "([Нн])я" .. macron, "%1jā")
	text = mw.ustring.gsub(text, "([Нн])ёа" .. macron, "%1jåå")	
	text = mw.ustring.gsub(text, "([Нн])ёа", "%1jå")	

	-- digraphs ie and ea
	text = mw.ustring.gsub(text, "([" .. consonant .. "])е" .. macron, "%1ie")
	text = mw.ustring.gsub(text, "([" .. consonant .. "])я" .. macron, "%1ea")
	
	-- initial j + vowels
	text = mw.ustring.gsub(text, "^" .. "ю" .. macron, "jū")
	text = mw.ustring.gsub(text, "^" .. "я" .. macron, "jā")
	text = mw.ustring.gsub(text, "^" .. "ӣ", "ji")
	text = mw.ustring.gsub(text, "^" .. "е" .. macron, "jie")
	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, "^" .. "Ӣ", "Ji")
	text = mw.ustring.gsub(text, "^" .. "Е" .. macron, "Jie")
	text = mw.ustring.gsub(text, "^" .. "ё" .. macron, "Jō")		

	text = mw.ustring.gsub(text, " " .. "ю" .. macron, " jū")
	text = mw.ustring.gsub(text, " " .. "я" .. macron, " jea")
	text = mw.ustring.gsub(text, " " .. "ӣ", " ji")
	text = mw.ustring.gsub(text, " " .. "e" .. macron, " jie")
	text = mw.ustring.gsub(text, " " .. "ё" .. macron, " jō")	
	text = mw.ustring.gsub(text, " " .. "Ю" .. macron, " jū")
	text = mw.ustring.gsub(text, " " .. "Я" .. macron, " jea")
	text = mw.ustring.gsub(text, " " .. "Ӣ", " ji")
	text = mw.ustring.gsub(text, " " .. "E" .. macron, " jie")
	text = mw.ustring.gsub(text, " " .. "Ё" .. macron, " jō")	

	text = mw.ustring.gsub(text, "че", "če")
	text = mw.ustring.gsub(text, "йе", "jje")
	
	-- hard sign between same consonants
	text = mw.ustring.gsub(text, "във", "v'v")
	text = mw.ustring.gsub(text, "лъл", "l'l")
	text = mw.ustring.gsub(text, "мъм", "m'm")	
	text = mw.ustring.gsub(text, "нън", "n'n")	
	text = mw.ustring.gsub(text, "със", "s's")	
	text = mw.ustring.gsub(text, "тът", "t't")	

	-- soft/semi-soft/hard signs
	text = mw.ustring.gsub(text, "([".. consonant .."])([ьҍъ])е", "%1%2je")
	text = mw.ustring.gsub(text, "([".. consonant .."])([ьҍъ])ё", "%1%2jo")
	text = mw.ustring.gsub(text, "([".. consonant .."])([ьҍъ])ю", "%1%2ju")	
	text = mw.ustring.gsub(text, "([".. consonant .."])([ьҍъ])я", "%1%2ja")	

	
	-- palatalization
	text = mw.ustring.gsub(text, "([БбВвГгДдЖжЗзКкЛлӅӆМмӍӎӇӈПпРрҎҏСсТтХхЦцШшЩщ])е", "%1’e")
	text = mw.ustring.gsub(text, "([БбВвГгДдЖжЗзКкЛлӅӆМмӍӎӇӈПпРрҎҏСсТтХхЦцЧчШшЩщ])ё", "%1’o")
	text = mw.ustring.gsub(text, "([БбВвГгДдЖжЗзКкЛлӅӆМмӍӎӇӈПпРрҎҏСсТтХхЦцЧчШшЩщ])ю", "%1’u")
	text = mw.ustring.gsub(text, "([БбВвГгДдЖжЗзКкЛлӅӆМмӍӎӇӈПпРрҎҏСсТтХхЦцЧчШшЩщ])я", "%1’a")	

	-- palatal н
	text = mw.ustring.gsub(text, "([НнӉӊ])е", "%1je")	
	text = mw.ustring.gsub(text, "([НнӉӊ])ё", "%1jo")
	text = mw.ustring.gsub(text, "([НнӉӊ])ю", "%1ju")
	text = mw.ustring.gsub(text, "([НнӉӊ])я", "%1ja")
	
	-- oa digraph
	text = mw.ustring.gsub(text, "О[Аа]" .. macron, "Åå")
	text = mw.ustring.gsub(text, "оа" .. macron, "åå")
	text = mw.ustring.gsub(text, "О[Аа]", "Å")
	text = mw.ustring.gsub(text, "оа", "å")
	
	-- ёa digraph
	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, "Ёа", "Jå")
	text = mw.ustring.gsub(text, "ёа", "jå")

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

return export