Module:xwo-translit

From Wiktionary, the free dictionary
Jump to navigation Jump to search

This module will transliterate Written Oirat language text. It is also used to transliterate Classical Tibetan. 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:xwo-translit/testcases.

Functions

[edit]
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 MACRON    = mw.ustring.char(0x0304)

local tt = {
	["ᠠ"] = "a",	["ᡄ"] = "e",	["ᡅ"] = "i",	["ᡆ"] = "o",	["ᡇ"] = "u",
	["ᡈ"] = "ö",	["ᡉ"] = "ü",
	["ᡋ"] = "b",    ["ᡌ"] = "p",    ["ᡏ"] = "m",    ["ᠯ"] = "l",	
	["ᠰ"] = "s",	["ᠱ"] = "š",   	["ᠨ"] = "n",   	["ᡍ"] = "x",  
	["ᡎ"] = "ɣ",    ["ᡐ"] = "t",    ["ᡑ"] = "d",   ["ᡔ"] = "c",
	["ᡒ"] = "č",    ["ᡓ"] = "ǰ",    ["ᡕ"] = "y",   ["ᠷ"] = "r", 
	["ᡖ"] = "w",    ["ᡙ"] = "h",    ["ᡘ"] = "gh",  ["ᡗ"] = "q",
	["ᡚ"] = "ž",    ["ᡛ"] = "ń",    ["ᡜ"] = "dz",  ["ᡊ"] = "ng",
	["ᠴ"] = "z",
	["ᡃ"] = MACRON, ["᠎"] = "-",	["︖"] = "?",	["︕"] = "!",
	["᠂"] = ",",	["᠃"] = ".",	[" "] = "-",	["᠊"] = "-"
}

function export.tr(text, lang, sc)
	local velar_conv = { ["x"] = "k", ["ɣ"] = "g" }
	text = mw.ustring.gsub(text, ".", tt)
	text = mw.ustring.gsub(text, "([xɣ])(.?)", function(velar, vowel)
		return ((mw.ustring.match(vowel, "[eiöü ]") or vowel == "")
			and mw.ustring.gsub(velar, "[xɣ]", velar_conv) or velar) .. vowel end)
	text = mw.ustring.gsub(text, "zi", "ji")
	return text
end

return export