မဝ်ဂျူ:Lana-translit

နူ ဝိက်ရှေန်နရဳ

Documentation for this module may be created at မဝ်ဂျူ:Lana-translit/doc

local export = {}
local gsub = mw.ustring.gsub
local u = mw.ustring.char

local tt = {
	-- consonants
	["ᨠ"] = "k", ["ᨡ"] = "ǩh", ["ᨢ"] = "Ķh", ["ᨣ"] = "kh", ["ᨤ"] = "kʹh", ["ᨥ"] = "ḳh", ["ᨦ"] = "ng",
	["ᨧ"] = "c", ["ᨨ"] = "c̄h", ["ᨩ"] = "ch", ["ᨪ"] = "s", ["ᨫ"] = "ć̣h", ["ᨬ"] = "ỵ",
	["ᨭ"] = "ţ", ["ᨮ"] = "țh", ["ᨯ"] = "d", ["ᨰ"] = "tʹh", ["ᨱ"] = "ṇ",
	["ᨲ"] = "t", ["ᨳ"] = "th", ["ᨴ"] = "th", ["ᨵ"] = "ṭh", ["ᨶ"] = "n",
	["ᨷ"] = "b", ["ᨸ"] = "p", ["ᨹ"] = "p̄h", ["ᨺ"] = "ḟ", ["ᨻ"] = "ph", ["ᨼ"] = "f", ["ᨽ"] = "ᵱh", ["ᨾ"] = "m",
	["ᨿ"] = "y", ["ᩀ"] = "y̱", ["ᩁ"] = "r", ["ᩂ"] = "v", ["ᩃ"] = "l", ["ᩄ"] = "ł", ["ᩅ"] = "w",
	["ᩆ"] = "ṩ", ["ᩇ"] = "s̄ā", ["ᩈ"] = "s̄", ["ᩉ"] = "ħ", ["ᩊ"] = "ḷ", ["ᩋ"] = "x", ["ᩌ"] = "ḥ",
	-- independent vowels
	["ᩍ"] = "xi", ["ᩎ"] = "xī", ["ᩏ"] = "xu", ["ᩐ"] = "xū", ["ᩑ"] = "x↶e", ["ᩒ"] = "x↶o",
	-- medials and miscellaneous
	["ᩓ"] = "l↶æ", ["ᩔ"] = "s̄*s̄", ["ᩕ"] = "*r", ["ᩖ"] = "*l", ["ᩗ"] = "*l", ["ᩘ"] = "ng*",
	["ᩙ"] = "ng*", ["ᩙ"] = "ph*", ["ᩜ"] = "*m", ["ᩝ"] = "*b", ["ᩞ"] = "*s̄",
	["᪢"] = "s̄wạrkh̒",
	-- dependent vowels and diacritics
	["᩠"] = "*", ["ᩡ"] = "a", ["ᩢ"] = "ạ", ["ᩣ"] = "ā", ["ᩤ"] = "ā", -- ignore bindu
	["ᩥ"] = "i", ["ᩦ"] = "ī", ["ᩧ"] = "ụ", ["ᩨ"] = "ū", ["ᩩ"] = "u", ["ᩪ"] = "ū",
	["ᩫ"] = "̆", ["ᩬ"] = "x", ["ᩭ"] = "xy",
	["ᩮ"] = "↶e", ["ᩯ"] = "↶æ", ["ᩰ"] = "↶o", ["ᩱ"] = "↶Ị", ["ᩲ"] = "↶l",
	["ᩳ"] = "x", ["ᩴ"] = "̊", ["᩵"] = "'", ["᩶"] = "̂",
	["᩺"] = "̒", ["᩻"] = "~", ["᩼"] = "̒", ["᩿"] = "ˌ",
	-- numerals
	["᪀"] = "0", ["᪁"] = "1", ["᪂"] = "2", ["᪃"] = "3", ["᪄"] = "4",
	["᪅"] = "5", ["᪆"] = "6", ["᪇"] = "7", ["᪈"] = "8", ["᪉"] = "9",
	["᪐"] = "0", ["᪑"] = "2", ["᪒"] = "2", ["᪓"] = "3", ["᪔"] = "4",
	["᪕"] = "5", ["᪖"] = "6", ["᪗"] = "7", ["᪘"] = "8", ["᪙"] = "9",
	-- punctuation marks
	["ᪧ"] = "«", ["᪨"] = "‡", ["᪩"] = ".", ["᪪"] = "‡", ["᪫"] = ".", ["᪬"] = "»",
	-- zero-width space (display it if it hides in a word)
	[u(0x200B)] = "‼",
}

function export.tr(text, lang, sc, debug_mode)

	if type(text) == "table" then -- called directly from a template
		text = text.args[1]
	end

	-- haang "ᩛ" can be ᨮ, ᨳ, or ᨻ
	text = gsub(text, "([ᨭ-ᨱ])ᩛ", "%1᩠ᨮ")
	text = gsub(text, "([ᨲ-ᨶ])ᩛ", "%1᩠ᨳ")
	text = gsub(text, "([ᨷ-ᨾ])ᩛ", "%1᩠ᨻ")

	text = gsub(text, ".", tt)

	text = gsub(text, "~%f[%s%p%z]", "«")
	text = gsub(text, "([k-ḥ]̱?)%*([k-ḥ]̱?)~", "%1~%2")

	text = gsub(text, "([k-ḥ]̱?)↶([eæoıị])", "%2%1")

	if lang == "pi" or lang == "sa" then
		text = gsub(text, "d", "ṯh")
		text = gsub(text, "b", "p")
		text = gsub(text, "เ([k-ḥ]̱?)า", "o%1") --TODO: what about "au" in Sanskrit?
		text = gsub(text, "%*", "ˌ")
	else
		text = gsub(text, "%*", "")
	end

	return text

end

return export