Module:mn-translit

Definition from Wiktionary, the free dictionary
Jump to: navigation, search

This module will transliterate Mongolian language text per WT:MN TR.

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:mn-translit/testcases.

Functions[edit]

tr(text, lang, sc)
Transliterates a given piece of text written in the script specified by sc, and language specified by lang. When the transliteration fails, returns nil.

local export = {}

local trfunc = {}

local tt_Cyrl = {
	["Щ"] = "Šč",	["щ"] = "šč",	["Ы"] = "Y",	["ы"] = "y",	["Э"] = "E",	["э"] = "e",	
	["Я"] = "Ja",	["я"] = "ja",	["У"] = "U",	["у"] = "u",	["С"] = "S",	["с"] = "s",	
	["Ч"] = "Č",	["ч"] = "č",	["Х"] = "H",	["х"] = "h",	["Ж"] = "Ž",	["ж"] = "ž",	
	["Д"] = "D",	["д"] = "d",	["В"] = "V",	["в"] = "v",	["А"] = "A",	["а"] = "a",	
	["М"] = "M",	["м"] = "m",	["О"] = "O",	["о"] = "o",	["И"] = "I",	["и"] = "i",	
	["К"] = "K",	["к"] = "k",	["Ш"] = "Š",	["ш"] = "š",	["Ъ"] = "ʺ",	["ъ"] = "ʺ",	
	["Ё"] = "Jo",	["ё"] = "jo",	["Ь"] = "ʹ",	["ь"] = "ʹ",	["Ю"] = "Ju",	["ю"] = "ju",	
	["Т"] = "T",	["т"] = "t",	["Р"] = "R",	["р"] = "r",	["Ц"] = "Ts",	["ц"] = "ts",	
	["Ф"] = "F",	["ф"] = "f",	["З"] = "Z",	["з"] = "z",	["Е"] = "E",	["е"] = "e",	
	["Г"] = "G",	["г"] = "g",	["Б"] = "B",	["б"] = "b",	["Н"] = "N",	["н"] = "n",	
	["П"] = "P",	["п"] = "p",	["Й"] = "J",	["й"] = "j",	["Л"] = "L",	["л"] = "l",	
	["Ү"] = "Ü",	["ү"] = "ü",	["Ө"] = "Ö",	["ө"] = "ö"
}

local tt_Mong = {
	["ᠠ"] = "a",	["ᠡ"] = "e",	["ᠢ"] = "i",	["ᠣ"] = "o",	["ᠤ"] = "u",
	["ᠥ"] = "ö",	["ᠦ"] = "ü",	["ᠧ"] = "ē",
	["ᠨ"] = "n",	["ᠩ"] = "ng",	["ᠪ"] = "b",	["ᠫ"] = "p",	
	["ᠬ"] = "q",	["ᢉ"] = "k",	["ᠭ"] = "ɣ",	["ᢉ"] = "g",
	["ᠮ"] = "m",	["ᠯ"] = "l",	["ᠰ"] = "s",	["ᠱ"] = "š",
	["ᠲ"] = "t",	["ᠳ"] = "d",	["ᠴ"] = "č",	["ᠵ"] = "ǰ",
	["ᠶ"] = "y",	["ᠷ"] = "r",	["ᠸ"] = "w",	["ᠹ"] = "f",
	["ᠺ"] = "g",	["ᠻ"] = "k",	["ᠼ"] = "c",	["ᠽ"] = "z",
	["ᠾ"] = "h",	["ᠿ"] = "ž",	["ᡀ"] = "lh",	["ᡁ"] = "zh",	["ᡂ"] = "ch"
}

function trfunc.Cyrl(text)
	text = mw.ustring.gsub(text, "([АОУЫЕЯЁЮИЕЪЬаоуыэяёюиеъь%A][\204\129\204\128]?)([Ее])",
		function (a, e)
			return a .. (e == "е" and "je" or "Je")
		end):gsub("^Е", "Je"):gsub("^е", "je")
	return (mw.ustring.gsub(text, ".", tt_Cyrl))
end

function trfunc.Mong(text)
	local velar_conv = { ["q"] = "k", ["ɣ"] = "g" }
	text = mw.ustring.gsub(text, ".", tt_Mong)
	text = mw.ustring.gsub(text, "([qɣ])(.?)", function(velar, vowel)
		return ((mw.ustring.match(vowel, "[eöü ]") or vowel == "")
			and mw.ustring.gsub(velar, "[qɣ]", velar_conv) or velar) .. vowel end)
	return text
end

function export.tr(text, lang, sc)
	if not sc then
		local m_utilities = require("Module:utilities")
		sc = m_utilities.detect_script(text, require("Module:languages").getLanguageByCode("mn"))
	end
	
	if trfunc[sc] then
		return trfunc[sc](text)
	end
end

return export