Nothing Special   »   [go: up one dir, main page]


This module will transliterate text in the Mongolian script. It is used to transliterate Buryat, Classical Mongolian, Daur, Mongolian, Sanskrit, Dukhan, Classical Tibetan, Middle Mongol, and Khamnigan Mongol. 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:Mong-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 gsub = mw.ustring.gsub
local match = mw.ustring.match

local export = {}

local chars = {
	["ᠠ"] = "a", ["ᠡ"] = "e",
	["ᠢ"] = "i",
	["ᠣ"] = "o", ["ᠤ"] = "u",
	["ᠥ"] = "ö", ["ᠦ"] = "ü",
	["ᠧ"] = "ē",
	["ᠨ"] = "n",
	["ᠩ"] = "ng",
	["ᠪ"] = "b", ["ᠫ"] = "p",
	["ᠬ"] = "q", ["ᠭ"] = "ɣ",
	["ᠮ"] = "m", ["ᠯ"] = "l",
	["ᠰ"] = "s", ["ᠱ"] = "š",
	["ᠲ"] = "t", ["ᠳ"] = "d",
	["ᠴ"] = "č", ["ᡸ"] = "š̤",
	["ᠵ"] = "ǰ", ["ᠶ"] = "y", ["ᠷ"] = "r",
	["ᠸ"] = "w",
	["ᠹ"] = "f",
	["ᠺ"] = "k", ["ᠻ"] = "k",
	["ᠼ"] = "c", ["ᠽ"] = "z",
	["ᠾ"] = "h",
	["ᠿ"] = "ř",
	["ᡀ"] = "lh",
	["ᡁ"] = "ž",
	["ᡂ"] = "č̭",
	["᠐"] = "0", ["᠑"] = "1", ["᠒"] = "2", ["᠓"] = "3",
	["᠔"] = "4", ["᠕"] = "5", ["᠖"] = "6", ["᠗"] = "7",
	["᠘"] = "8", ["᠙"] = "9",
	["᠀"] = "∞", ["᠁"] = "…", ["᠂"] = ",", ["᠃"] = ".", ["᠄"] = ":", ["᠅"] = "::",
	["︖"] = "?", ["︕"] = "!",
	[" "] = "-", ["᠊"] = "-", ["᠎"] = "-",
	["᠋"] = "", ["᠌"] = "", ["᠍"] = "", ["᠏"] = "",
}

local front_vowel = {
	["ɣ"] = "g",
	["q"] = "k"
}

function export.tr(text, lang, sc)
	if sc ~= "Mong" then
		return nil
	end
	local bad_diphthong = match(text, "ᠥᠶ?ᠢ")
	if bad_diphthong then
		error("Diphthong " .. diphthong .. " does not exist. Please replace with " .. gsub(bad_diphthong, "ᠥ", "ᠦ") .. ".")
	end
	text = gsub(text, ".", chars)
	text = gsub(text, "[ɣq]%f[eēiöü%z%s%p]", front_vowel)
	return text
end

return export