Module:Wp/nod/translit-Thai

From Wikimedia Incubator

Documentation for this module may be created at Module:Wp/nod/translit-Thai/doc

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

local PAGENAME = mw.title.getCurrentTitle().prefixedText

local tt = {
	-- consonants
	["ᨠ"] = "ก", ["ᨡ"] = "ข", ["ᨢ"] = "ฃ", ["ᨣ"] = "ค", ["ᨤ"] = "ฅ", ["ᨥ"] = "ฆ", ["ᨦ"] = "ง",
	["ᨧ"] = "จ", ["ᨨ"] = "ฉ", ["ᨩ"] = "ช", ["ᨪ"] = "ซ", ["ᨫ"] = "ฌ", ["ᨬ"] = "ญ",
	["ᨭ"] = "ฏ", ["ᨮ"] = "ฐ", ["ᨯ"] = "ด", ["ᨰ"] = "ฒ", ["ᨱ"] = "ณ",
	["ᨲ"] = "ต", ["ᨳ"] = "ถ", ["ᨴ"] = "ท", ["ᨵ"] = "ธ", ["ᨶ"] = "น",
	["ᨷ"] = "บ", ["ᨸ"] = "ป", ["ᨹ"] = "ผ", ["ᨺ"] = "ฝ", ["ᨻ"] = "พ", ["ᨼ"] = "ฟ", ["ᨽ"] = "ภ", ["ᨾ"] = "ม",
	["ᨿ"] = "ย", ["ᩀ"] = "ย̱", ["ᩁ"] = "ร", ["ᩂ"] = "ฤ", ["ᩃ"] = "ล", ["ᩄ"] = "ฦ", ["ᩅ"] = "ว",
	["ᩆ"] = "ศ", ["ᩇ"] = "ษ", ["ᩈ"] = "ส", ["ᩉ"] = "ห", ["ᩊ"] = "ฬ", ["ᩋ"] = "อ", ["ᩌ"] = "ฮ",
	-- independent vowels
	["ᩍ"] = "อิ", ["ᩎ"] = "อี", ["ᩏ"] = "อุ", ["ᩐ"] = "อู", ["ᩑ"] = "อ↶เ", ["ᩒ"] = "อ↶โ",
	-- medials and miscellaneous
	["ᩓ"] = "ล↶แ", ["ᩔ"] = "สส", ["ᩕ"] = "ร", ["ᩖ"] = "ล", ["ᩗ"] = "ล", ["ᩘ"] = "ง",
	["᪢"] = "สวัรค์",
	-- dependent vowels and diacritics
	["᩠"] = "", ["ᩡ"] = "ะ", ["ᩢ"] = "ั", ["ᩣ"] = "า", ["ᩤ"] = "า", -- ignore bindu
	["ᩥ"] = "ิ", ["ᩦ"] = "ี", ["ᩧ"] = "ึ", ["ᩨ"] = "ื", ["ᩩ"] = "ุ", ["ᩪ"] = "ู",
	["ᩫ"] = "็", ["ᩬ"] = "อ", ["ᩭ"] = "อย",
	["ᩮ"] = "↶เ", ["ᩯ"] = "↶แ", ["ᩰ"] = "↶โ", ["ᩱ"] = "↶ไ", ["ᩲ"] = "↶ใ",
	["ᩳ"] = "↶เา", ["ᩴ"] = "ํ", ["᩵"] = "่", ["᩶"] = "้",
	["᩺"] = "์", ["᩻"] = "ๆ", ["᩼"] = "์", ["᩿"] = "ฺ",
	-- numerals
	["᪀"] = "0", ["᪁"] = "1", ["᪂"] = "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)

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

	-- deal with haang "ᩛ"
	text = gsub(text, "([ᨭ-ᨱ])ᩛ", "%1᩠ᨮ")
	text = gsub(text, "([ᨷ-ᨾ])ᩛ", "%1᩠ᨻ")

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

	text = gsub(text, "([ก-ฮ]̱?)↶([เแโใไ])", "%2%1")

	return text

end

function export.trpage(page)

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

	local text = mw.title.new(page):getContent()

	-- remove any self calling
	text = gsub(text, "%{%{#invoke:.+%}%}", "")
	text = gsub(text, "%{%{Wp/nod/translit%}%}", "")

	text = gsub(text, "<ref.-</ref>", "")
	text = gsub(text, "<references/?>", "")

	text = export.tr(text)

	return text

end

return export