Jump to content

Module:Glag-translit

From Wiktionary, the free dictionary

This module will transliterate text in the Glagolitic script. It is used to transliterate Old Church Slavonic and Old Novgorodian. 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:Glag-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 letters = {
	["common"] = {
		["Ⰰ"] = 'A',
		["ⰰ"] = 'a',
		["Ⱝ"] = 'A',
		["ⱝ"] = 'a',
		["Ⰱ"] = 'B',
		["ⰱ"] = 'b',
		["Ⰲ"] = 'V',
		["ⰲ"] = 'v',
		["Ⰳ"] = 'G',
		["ⰳ"] = 'g',
		["Ⰴ"] = 'D',
		["ⰴ"] = 'd',
		["Ⰵ"] = 'E',
		["ⰵ"] = 'e',
		["Ⰶ"] = 'Ž',
		["ⰶ"] = 'ž',
		["Ⰷ"] = 'Dz',
		["ⰷ"] = 'dz',
		["Ⰸ"] = 'Z',
		["ⰸ"] = 'z',
		["Ⰹ"] = 'I',
		["ⰹ"] = 'i',
		["Ⰺ"] = 'I',
		["ⰺ"] = 'i',
		["Ⰻ"] = 'I',
		["ⰻ"] = 'i',
		["Ⰼ"] = 'Đ',
		["ⰼ"] = 'đ',
		["Ⰽ"] = 'K',
		["ⰽ"] = 'k',
		["Ⰾ"] = 'L',
		["ⰾ"] = 'l',
		["Ⰿ"] = 'M',
		["ⰿ"] = 'm',
		["Ⱞ"] = 'M',
		["ⱞ"] = 'm',
		["Ⱀ"] = 'N',
		["ⱀ"] = 'n',
		["Ⱁ"] = 'O',
		["ⱁ"] = 'o',
		["Ⱉ"] = 'O',
		["ⱉ"] = 'o',
		["Ⱂ"] = 'P',
		["ⱂ"] = 'p',
		["Ⱃ"] = 'R',
		["ⱃ"] = 'r',
		["Ⱄ"] = 'S',
		["ⱄ"] = 's',
		["Ⱅ"] = 'T',
		["ⱅ"] = 't',
		["Ⱆ"] = 'U',
		["ⱆ"] = 'u',
		["Ⱇ"] = 'F',
		["ⱇ"] = 'f',
		["Ⱈ"] = 'X',
		["ⱈ"] = 'x',
		["Ⱒ"] = 'X',
		["ⱒ"] = 'x',
		["Ⱌ"] = 'C',
		["ⱌ"] = 'c',
		["Ⱍ"] = 'Č',
		["ⱍ"] = 'č',
		["Ⱎ"] = 'Š',
		["ⱎ"] = 'š',
		["Ⱏ"] = 'Ŭ',
		["ⱏ"] = 'ŭ',
		["Ⱐ"] = 'Ĭ',
		["ⱐ"] = 'ĭ',
		["Ⱜ"] = 'Ĭ',
		["ⱜ"] = 'ĭ',
		["Ⱑ"] = 'Ě',
		["ⱑ"] = 'ě',
		["Ⱓ"] = 'Ju',
		["ⱓ"] = 'ju',
		["Ⱔ"] = 'Ę',
		["ⱔ"] = 'ę',
		["Ⱕ"] = 'Y̨',
		["ⱕ"] = 'y̨',
		["Ⱗ"] = 'Ję',
		["ⱗ"] = 'ję',
		["Ⱘ"] = 'Ǫ',
		["ⱘ"] = 'ǫ',
		["Ⱖ"] = 'Ǫ',
		["ⱖ"] = 'ǫ',
		["Ⱙ"] = 'Jǫ',
		["ⱙ"] = 'jǫ',
		["Ⱚ"] = 'Θ',
		["ⱚ"] = 'θ',
		["Ⱛ"] = 'Ü',
		["ⱛ"] = 'ü',
		["Ⱋ"] = 'Št',
		["ⱋ"] = 'št'
	},
	["zle-ono"] = {
		["Ⱌ"] = 'Ć',
		["ⱌ"] = 'ć',
		["Ⱍ"] = 'Ć',
		["ⱍ"] = 'ć',
		["Ⱋ"] = 'Ść',
		["ⱋ"] = 'ść'
	}
}

local digraphs = {
	["common"] = {
		["Ⱏ[ⰉⰊⰋⰹⰺⰻ]"] = "Y", ["ⱏ[ⰹⰺⰻ]"] = "y",
	},
	["zle-ono"] = {
		["ⱏ[ⰹⰺⰻ]"] = 'ŷi',
	}
}

function export.tr(text, lang, sc)
	if not sc then
		sc = require("Module:languages").getByCode(lang):findBestScript(text):getCode()
	end

	local function digraph_subst(digraphs)
		for key, repl in pairs(digraphs) do
			text = mw.ustring.gsub(text, key, repl)
		end
	end

	if sc ~= "Glag" then
		text = nil
	else
		-- Transliterate the kamora as prime
		text = mw.ustring.gsub(text, U(0x0484), "ʹ")

		if digraphs[lang] then
			digraph_subst(digraphs[lang])
		end
		digraph_subst(digraphs["common"])

		if letters[lang] then
			text = mw.ustring.gsub(text, '.', letters[lang])
		end
		text = mw.ustring.gsub(text, '.', letters["common"])

		-- Transliterate the titlo and vzmet as colon.
		text = mw.ustring.gsub(text, "[" .. U(0x0483) .. U(0xA66F) .. "]", ":")
	end
	
	return text
end

return export