Module:Glag-translit

Hello, you have come here looking for the meaning of the word Module:Glag-translit. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:Glag-translit, but we will also tell you about its etymology, its characteristics and you will know how to say Module:Glag-translit in singular and plural. Everything you need to know about the word Module:Glag-translit you have here. The definition of the word Module:Glag-translit will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:Glag-translit, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

This module will transliterate text in the Glagolitic script. It is used to transliterate Old Church Slavonic, Old Novgorodian, and Church Slavonic. 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 = {
	 = {
		 = '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'
	},
	 = {
		 = 'Ć',
		 = 'ć',
		 = 'Ć',
		 = 'ć',
		 = 'Ść',
		 = 'ść'
	}
}

local digraphs = {
	 = {
		"] = "Y", "] = "y",
	},
	 = {
		"] = 'ŷ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 then
			digraph_subst(digraphs)
		end
		digraph_subst(digraphs)

		if letters then
			text = mw.ustring.gsub(text, '.', letters)
		end
		text = mw.ustring.gsub(text, '.', letters)

		-- Transliterate the titlo and vzmet as colon.
		text = mw.ustring.gsub(text, "", ":")
	end
	
	return text
end

return export