Module:Mong-translit: Difference between revisions

From Linguifex
Jump to navigation Jump to search
No edit summary
m 1 revision imported
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
local gsub = mw.ustring.gsub
local match = mw.ustring.match
local export = {}
local export = {}


local oneChar = {
local chars = {
["ᠠ"] = "a", ["ᠡ"] = "e", ["ᠢ"] = "i", ["ᡶ"] = "f", ["ᠣ"] = "o", ["ᠤ"] = "u", ["ᠥ"] = "ö", ["ᠦ"] = "ü", ["ᠧ"] = "ē", ["ᠨ"] = "n", ["ᠩ"] = "ŋ", ["ᠪ"] = "b", ["ᠫ"] = "p", ["ᠬ"] = "q", ["ᠭ"] = "ɣ", ["ᠮ"] = "m", ["ᠯ"] = "l", ["ᠰ"] = "s", ["ᠱ"] = "š", ["ᠲ"] = "t", ["ᠳ"] = "d", ["ᠴ"] = "č", ["ᡸ"] = "š̤", ["ᠵ"] = "ǰ", ["ᠶ"] = "y", ["ᠷ"] = "r", ["ᠸ"] = "w", ["ᠹ"] = "f", ["ᠺ"] = "k", ["ᠻ"] = "kh", ["ᠼ"] = "c", ["ᠽ"] = "z", ["ᠾ"] = "h", ["ᠿ"] = "ž", ["ᡀ"] = "lh", ["ᡁ"] = "zh", ["ᡂ"] = "ch",
["ᠠ"] = "a", ["ᠡ"] = "e",
["᠐"] = "0", ["᠑"] = "1", ["᠒"] = "2", ["᠓"] = "3", ["᠔"] = "4", ["᠕"] = "5", ["᠖"] = "6", ["᠗"] = "7", ["᠘"] = "8", ["᠙"] = "9",
["ᠢ"] = "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 twoChars = {
local front_vowel = {
["ᠠᠢ"] = "ai̯", ["ᠡᠢ"] = "ei̯", ["ᠣᠢ"] = "oi̯", ["ᠤᠢ"] = "ui̯", ["ᠦᠢ"] = "üi̯", ["ᠧᠢ"] = "ēi̯"
["ɣ"] = "g",
["q"] = "k"
}
}


Line 15: Line 45:
if sc ~= "Mong" then
if sc ~= "Mong" then
return nil
return nil
elseif mw.ustring.match(text, "ᠥᠢ") or mw.ustring.match(text, "ᠥᠶᠢ") then
local diphthong = mw.ustring.match(text, "ᠥᠶ?ᠢ")
error("Diphthong " .. diphthong .. " does not exist. Please replace with " .. mw.ustring.gsub(diphthong, "ᠥ", "ᠦ") .. ".")
end
end
for digraph, replacement in pairs(twoChars) do
local bad_diphthong = match(text, "ᠥᠶ?ᠢ")
text = string.gsub(text, digraph, replacement)
if bad_diphthong then
error("Diphthong " .. diphthong .. " does not exist. Please replace with " .. gsub(bad_diphthong, "ᠥ", "ᠦ") .. ".")
end
end
text = mw.ustring.gsub(text, ".", oneChar)
text = gsub(text, ".", chars)
text = mw.ustring.gsub(text, "q([eöü ])", "k%1")
text = gsub(text, "[ɣq]%f[eēiöü%z%s%p]", front_vowel)
text = mw.ustring.gsub(text, "q$", "k")
text = mw.ustring.gsub(text, "ɣ([eöü ])", "g%1")
text = mw.ustring.gsub(text, "ɣ$", "g")
return text
return text
end
end


return export
return export

Latest revision as of 12:46, 21 April 2026

Documentation for this module may be created at Module:Mong-translit/doc

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