ข้ามไปเนื้อหา

มอดูล:pi-alt

จาก วิกิพจนานุกรม พจนานุกรมเสรี

-- For Lao script, see https://www.unicode.org/charts/PDF/U0E80.pdf (Unicode 12.0+)

local export = {}

local gsub = mw.ustring.gsub
local match = mw.ustring.match
local sub = mw.ustring.sub
local u = mw.ustring.char

local links = require("Module:links")
local labels = require("Module:labels")
local scripts = require("Module:scripts")
local Array = require("Module:array")

local lang = require("Module:languages").getByCode("pi")
local PAGENAME = mw.title.getCurrentTitle().text
local currentScript = lang:findBestScript(PAGENAME)

-- ordered by [[Module:languages/data2]]
local sc_table = {"Thai", "Brah", "Deva", "Beng", "Sinh", "Mymr", "Lana", "Laoo", "Khmr", "Latn"}

-- whatever ordering
local c = {
	["Deva"] = {
		["ก"] = "क", ["ข"] = "ख", ["ค"] = "ग", ["ฆ"] = "घ", ["ง"] = "ङ",
		["จ"] = "च", ["ฉ"] = "छ", ["ช"] = "ज", ["ฌ"] = "झ", ["ญ"] = "ञ",
		["ฏ"] = "ट", ["ฐ"] = "ठ", ["ฑ"] = "ड", ["ฒ"] = "ढ", ["ณ"] = "ण",
		["ต"] = "त", ["ถ"] = "थ", ["ท"] = "द", ["ธ"] = "ध", ["น"] = "न",
		["ป"] = "प", ["ผ"] = "फ", ["พ"] = "ब", ["ภ"] = "भ", ["ม"] = "म",
		["ย"] = "य", ["ร"] = "र", ["ล"] = "ल", ["ว"] = "व", ["ส"] = "स",
		["ห"] = "ह", ["ฬ"] = "ळ",
		["ํ"] = "ं",
		[""] = "",
	},
	["Beng"] = {
		["ก"] = "ক", ["ข"] = "খ", ["ค"] = "গ", ["ฆ"] = "ঘ", ["ง"] = "ঙ",
		["จ"] = "চ", ["ฉ"] = "ছ", ["ช"] = "জ", ["ฌ"] = "ঝ", ["ญ"] = "ঞ",
		["ฏ"] = "ট", ["ฐ"] = "ঠ", ["ฑ"] = "ড", ["ฒ"] = "ঢ", ["ณ"] = "ণ",
		["ต"] = "ত", ["ถ"] = "থ", ["ท"] = "দ", ["ธ"] = "ধ", ["น"] = "ন",
		["ป"] = "প", ["ผ"] = "ফ", ["พ"] = "ব", ["ภ"] = "ভ", ["ม"] = "ম",
		["ย"] = "য", ["ร"] = "র", ["ล"] = "ল", ["ว"] = "ৰ", ["ส"] = "স",
		["ห"] = "হ", ["ฬ"] = "ল়",
		["ํ"] = "ং",
		[""] = "",
	},
	["Brah"] = {
		["ก"] = "𑀓", ["ข"] = "𑀔", ["ค"] = "𑀕", ["ฆ"] = "𑀖", ["ง"] = "𑀗",
		["จ"] = "𑀘", ["ฉ"] = "𑀙", ["ช"] = "𑀚", ["ฌ"] = "𑀛", ["ญ"] = "𑀜",
		["ฏ"] = "𑀝", ["ฐ"] = "𑀞", ["ฑ"] = "𑀟", ["ฒ"] = "𑀠", ["ณ"] = "𑀡",
		["ต"] = "𑀢", ["ถ"] = "𑀣", ["ท"] = "𑀤", ["ธ"] = "𑀥", ["น"] = "𑀦",
		["ป"] = "𑀧", ["ผ"] = "𑀨", ["พ"] = "𑀩", ["ภ"] = "𑀪", ["ม"] = "𑀫",
		["ย"] = "𑀬", ["ร"] = "𑀭", ["ล"] = "𑀮", ["ว"] = "𑀯", ["ส"] = "𑀲",
		["ห"] = "𑀳", ["ฬ"] = "𑀴",
		["ํ"] = "𑀁",
		[""] = "",
	},
	["Khmr"] = {
		["ก"] = "ក", ["ข"] = "ខ", ["ค"] = "គ", ["ฆ"] = "ឃ", ["ง"] = "ង",
		["จ"] = "ច", ["ฉ"] = "ឆ", ["ช"] = "ជ", ["ฌ"] = "ឈ", ["ญ"] = "ញ",
		["ฏ"] = "ដ", ["ฐ"] = "ឋ", ["ฑ"] = "ឌ", ["ฒ"] = "ឍ", ["ณ"] = "ណ",
		["ต"] = "ត", ["ถ"] = "ថ", ["ท"] = "ទ", ["ธ"] = "ធ", ["น"] = "ន",
		["ป"] = "ប", ["ผ"] = "ផ", ["พ"] = "ព", ["ภ"] = "ភ", ["ม"] = "ម",
		["ย"] = "យ", ["ร"] = "រ", ["ล"] = "ល", ["ว"] = "វ", ["ส"] = "ស",
		["ห"] = "ហ", ["ฬ"] = "ឡ",
		["ํ"] = "ំ",
		[""] = "",
	},
	["Mymr"] = {
		["ก"] = "က", ["ข"] = "ခ", ["ค"] = "ဂ", ["ฆ"] = "ဃ", ["ง"] = "င",
		["จ"] = "စ", ["ฉ"] = "ဆ", ["ช"] = "ဇ", ["ฌ"] = "ဈ", ["ญ"] = "ဉ",
		["ฏ"] = "ဋ", ["ฐ"] = "ဌ", ["ฑ"] = "ဍ", ["ฒ"] = "ဎ", ["ณ"] = "ဏ",
		["ต"] = "တ", ["ถ"] = "ထ", ["ท"] = "ဒ", ["ธ"] = "ဓ", ["น"] = "န",
		["ป"] = "ပ", ["ผ"] = "ဖ", ["พ"] = "ဗ", ["ภ"] = "ဘ", ["ม"] = "မ",
		["ย"] = "ယ", ["ร"] = "ရ", ["ล"] = "လ", ["ว"] = "ဝ", ["ส"] = "သ",
		["ห"] = "ဟ", ["ฬ"] = "ဠ",
		["ํ"] = "ံ",
		[""] = "",
	},
	["Sinh"] = {
		["ก"] = "ක", ["ข"] = "ඛ", ["ค"] = "ග", ["ฆ"] = "ඝ", ["ง"] = "ඞ",
		["จ"] = "ච", ["ฉ"] = "ඡ", ["ช"] = "ජ", ["ฌ"] = "ඣ", ["ญ"] = "ඤ",
		["ฏ"] = "ට", ["ฐ"] = "ඨ", ["ฑ"] = "ඩ", ["ฒ"] = "ඪ", ["ณ"] = "ණ",
		["ต"] = "ත", ["ถ"] = "ථ", ["ท"] = "ද", ["ธ"] = "ධ", ["น"] = "න",
		["ป"] = "ප", ["ผ"] = "ඵ", ["พ"] = "බ", ["ภ"] = "භ", ["ม"] = "ම",
		["ย"] = "ය", ["ร"] = "ර", ["ล"] = "ල", ["ว"] = "ව", ["ส"] = "ස",
		["ห"] = "හ", ["ฬ"] = "ළ",
		["ํ"] = "ං",
		[""] = "",
	},
	["Lana"] = {
		["ก"] = "ᨠ", ["ข"] = "ᨡ", ["ค"] = "ᨣ", ["ฆ"] = "ᨥ", ["ง"] = "ᨦ",
		["จ"] = "ᨧ", ["ฉ"] = "ᨨ", ["ช"] = "ᨩ", ["ฌ"] = "ᨫ", ["ญ"] = "ᨬ",
		["ฏ"] = "ᨭ", ["ฐ"] = "ᨮ", ["ฑ"] = "ᨯ", ["ฒ"] = "ᨰ", ["ณ"] = "ᨱ",
		["ต"] = "ᨲ", ["ถ"] = "ᨳ", ["ท"] = "ᨴ", ["ธ"] = "ᨵ", ["น"] = "ᨶ",
		["ป"] = "ᨷ", ["ผ"] = "ᨹ", ["พ"] = "ᨻ", ["ภ"] = "ᨽ", ["ม"] = "ᨾ",
		["ย"] = "ᨿ", ["ร"] = "ᩁ", ["ล"] = "ᩃ", ["ว"] = "ᩅ", ["ส"] = "ᩈ",
		["ห"] = "ᩉ", ["ฬ"] = "ᩊ",
		["ํ"] = "ᩴ",
		[""] = "",
	},
	["Laoo"] = {
		["ก"] = "ກ", ["ข"] = "ຂ", ["ค"] = "ຄ", ["ฆ"] = "ຆ", ["ง"] = "ງ",
		["จ"] = "ຈ", ["ฉ"] = "ຉ", ["ช"] = "ຊ", ["ฌ"] = "ຌ", ["ญ"] = "ຎ",
		["ฏ"] = "ຏ", ["ฐ"] = "ຐ", ["ฑ"] = "ຑ", ["ฒ"] = "ຒ", ["ณ"] = "ຓ",
		["ต"] = "ຕ", ["ถ"] = "ຖ", ["ท"] = "ທ", ["ธ"] = "ຘ", ["น"] = "ນ",
		["ป"] = "ປ", ["ผ"] = "ຜ", ["พ"] = "ພ", ["ภ"] = "ຠ", ["ม"] = "ມ",
		["ย"] = "ຍ", ["ร"] = "ຣ", ["ล"] = "ລ", ["ว"] = "ວ", ["ส"] = "ສ",
		["ห"] = "ຫ", ["ฬ"] = "ຬ",
		["ํ"] = "ໍ",
		[""] = "",
	},
	["Latn"] = {
		["ก"] = "k", ["ข"] = "kh", ["ค"] = "g", ["ฆ"] = "gh", ["ง"] = "ṅ",
		["จ"] = "c", ["ฉ"] = "ch", ["ช"] = "j", ["ฌ"] = "jh", ["ญ"] = "ñ",
		["ฏ"] = "ṭ", ["ฐ"] = "ṭh", ["ฑ"] = "ḍ", ["ฒ"] = "ḍh", ["ณ"] = "ṇ",
		["ต"] = "t", ["ถ"] = "th", ["ท"] = "d", ["ธ"] = "dh", ["น"] = "n",
		["ป"] = "p", ["ผ"] = "ph", ["พ"] = "b", ["ภ"] = "bh", ["ม"] = "m",
		["ย"] = "y", ["ร"] = "r", ["ล"] = "l", ["ว"] = "v", ["ส"] = "s",
		["ห"] = "h", ["ฬ"] = "ḷ",
		["ํ"] = "ṃ",
		[""] = "",
	},
}

local iv = {
	["Deva"] = {
		["อ"] = "अ", ["อา"] = "आ",
		["อิ"] = "इ", ["อี"] = "ई",
		["อุ"] = "उ", ["อู"] = "ऊ",
		["อเ"] = "ए",
		["อโ"] = "ओ",
	},
	["Beng"] = {
		["อ"] = "অ", ["อา"] = "আ",
		["อิ"] = "ই", ["อี"] = "ঈ",
		["อุ"] = "উ", ["อู"] = "ঊ",
		["อเ"] = "এ",
		["อโ"] = "ও",
	},
	["Brah"] = {
		["อ"] = "𑀅", ["อา"] = "𑀆",
		["อิ"] = "𑀇", ["อี"] = "𑀈",
		["อุ"] = "𑀉", ["อู"] = "𑀊",
		["อเ"] = "𑀏",
		["อโ"] = "𑀑",
	},
	["Khmr"] = {
		["อ"] = "អ", ["อา"] = "អា",
		["อิ"] = "ឥ", ["อี"] = "ឦ",
		["อุ"] = "ឧ", ["อู"] = "ឨ",
		["อเ"] = "ឯ",
		["อโ"] = "ឲ",
	},
	["Mymr"] = {
		["อ"] = "အ", ["อา"] = "အာ",
		["อิ"] = "ဣ", ["อี"] = "ဤ",
		["อุ"] = "ဥ", ["อู"] = "ဦ",
		["อเ"] = "ဧ",
		["อโ"] = "ဩ",
	},
	["Sinh"] = {
		["อ"] = "අ", ["อา"] = "ආ",
		["อิ"] = "ඉ", ["อี"] = "ඊ",
		["อุ"] = "උ", ["อู"] = "ඌ",
		["อเ"] = "එ",
		["อโ"] = "ඔ",
	},
	["Lana"] = {
		["อ"] = "ᩋ", ["อา"] = "ᩋᩣ",
		["อิ"] = "ᩍ", ["อี"] = "ᩎ",
		["อุ"] = "ᩏ", ["อู"] = "ᩐ",
		["อเ"] = "ᩑ",
		["อโ"] = "ᩋᩰ",
	},
	["Laoo"] = {
		["อ"] = "ອ", ["อา"] = "ອາ",
		["อิ"] = "ອິ", ["อี"] = "ອີ",
		["อุ"] = "ອຸ", ["อู"] = "ອູ",
		["อเ"] = "ອເ",
		["อโ"] = "ອໂ",
	},
	["Latn"] = {
		["อ"] = "a", ["อา"] = "ā",
		["อิ"] = "i", ["อี"] = "ī",
		["อุ"] = "u", ["อู"] = "ū",
		["อเ"] = "e",
		["อโ"] = "o",
	},
}

local dv = {
	["Deva"] = {
		[""] = "", ["า"] = "ा",
		["ิ"] = "ि", ["ี"] = "ी",
		["ุ"] = "ु", ["ู"] = "ू",
		["เ"] = "े",
		["โ"] = "ो",
	},
	["Beng"] = {
		[""] = "", ["า"] = "া",
		["ิ"] = "ি", ["ี"] = "ী",
		["ุ"] = "ু", ["ู"] = "ূ",
		["เ"] = "ে",
		["โ"] = "ো",
	},
	["Brah"] = {
		[""] = "", ["า"] = "𑀸",
		["ิ"] = "𑀺", ["ี"] = "𑀻",
		["ุ"] = "𑀼", ["ู"] = "𑀽",
		["เ"] = "𑁂",
		["โ"] = "𑁄",
	},
	["Khmr"] = {
		[""] = "", ["า"] = "ា",
		["ิ"] = "ិ", ["ี"] = "ី",
		["ุ"] = "ុ", ["ู"] = "ូ",
		["เ"] = "េ",
		["โ"] = "ោ",
	},
	["Mymr"] = {
		[""] = "", ["า"] = "ာ",
		["ิ"] = "ိ", ["ี"] = "ီ",
		["ุ"] = "ု", ["ู"] = "ူ",
		["เ"] = "ေ",
		["โ"] = "ော",
	},
	["Sinh"] = {
		[""] = "", ["า"] = "ා",
		["ิ"] = "ි", ["ี"] = "ී",
		["ุ"] = "ු", ["ู"] = "ූ",
		["เ"] = "ෙ",
		["โ"] = "ො",
	},
	["Lana"] = {
		[""] = "", ["า"] = "ᩣ",
		["ิ"] = "ᩥ", ["ี"] = "ᩦ",
		["ุ"] = "ᩩ", ["ู"] = "ᩪ",
		["เ"] = "ᩮ",
		["โ"] = "ᩮᩣ",
	},
	["Laoo"] = {
		[""] = "", ["า"] = "າ",
		["ิ"] = "ິ", ["ี"] = "ີ",
		["ุ"] = "ຸ", ["ู"] = "ູ",
		["เ"] = "ເ",
		["โ"] = "ໂ",
	},
	["Latn"] = {
		[""] = "a", ["า"] = "ā",
		["ิ"] = "i", ["ี"] = "ī",
		["ุ"] = "u", ["ู"] = "ū",
		["เ"] = "e",
		["โ"] = "o",
	},
}

local s = {
	["Deva"] = {
		["0"] = "०", ["1"] = "१", ["2"] = "२", ["3"] = "३", ["4"] = "४",
		["5"] = "५", ["6"] = "६", ["7"] = "७", ["8"] = "८", ["9"] = "९",
		["."] = "॥", [","] = "।", ["-"] = "-",
	},
	["Beng"] = {
		["0"] = "০", ["1"] = "১", ["2"] = "২", ["3"] = "৩", ["4"] = "৪",
		["5"] = "৫", ["6"] = "৬", ["7"] = "৭", ["8"] = "৮", ["9"] = "৯",
		["."] = ".", [","] = ",", ["-"] = "-",
	},
	["Brah"] = {
		["0"] = "𑁦", ["1"] = "𑁧", ["2"] = "𑁨", ["3"] = "𑁩", ["4"] = "𑁪",
		["5"] = "𑁫", ["6"] = "𑁬", ["7"] = "𑁭", ["8"] = "𑁮", ["9"] = "𑁯",
		["."] = "𑁈", [","] = "𑁇", ["-"] = "-",
	},
	["Khmr"] = {
		["0"] = "០", ["1"] = "១", ["2"] = "២", ["3"] = "៣", ["4"] = "៤",
		["5"] = "៥", ["6"] = "៦", ["7"] = "៧", ["8"] = "៨", ["9"] = "៩",
		["."] = "៕", [","] = "។", ["-"] = "-",
	},
	["Mymr"] = {
		["0"] = "၀", ["1"] = "၁", ["2"] = "၂", ["3"] = "၃", ["4"] = "၄",
		["5"] = "၅", ["6"] = "၆", ["7"] = "၇", ["8"] = "၈", ["9"] = "၉",
		["."] = "။", [","] = "၊", ["-"] = "-",
	},
	["Sinh"] = {
		["0"] = "0", ["1"] = "1", ["2"] = "2", ["3"] = "3", ["4"] = "4",
		["5"] = "5", ["6"] = "6", ["7"] = "7", ["8"] = "8", ["9"] = "9",
		["."] = ".", [","] = ",", ["-"] = "-",
	},
	["Lana"] = {
		["0"] = "᪐", ["1"] = "᪑", ["2"] = "᪒", ["3"] = "᪓", ["4"] = "᪔",
		["5"] = "᪕", ["6"] = "᪖", ["7"] = "᪗", ["8"] = "᪘", ["9"] = "᪙",
		["."] = "᪩", [","] = "᪨", ["-"] = "-",
	},
	["Laoo"] = {
		["0"] = "໐", ["1"] = "໑", ["2"] = "໒", ["3"] = "໓", ["4"] = "໔",
		["5"] = "໕", ["6"] = "໖", ["7"] = "໗", ["8"] = "໘", ["9"] = "໙",
		["."] = "ຯຯ", [","] = "ຯ", ["-"] = "-",
	},
	["Latn"] = {
		["0"] = "0", ["1"] = "1", ["2"] = "2", ["3"] = "3", ["4"] = "4",
		["5"] = "5", ["6"] = "6", ["7"] = "7", ["8"] = "8", ["9"] = "9",
		["."] = ".", [","] = ",", ["-"] = "-",
	},
}

local join = {
	["Deva"] = "्",
	["Beng"] = "্",
	["Brah"] = "𑁆",
	["Khmr"] = "្",
	["Mymr"] = "္",
	["Sinh"] = u(0x200d, 0x0dca),
	["Lana"] = "᩠",
	["Laoo"] = "຺",
	["Latn"] = "",
}

local kill = {
	["Deva"] = "्",
	["Beng"] = "্",
	["Brah"] = "𑁆",
	["Khmr"] = "៑",
	["Mymr"] = "်",
	["Sinh"] = "්",
	["Lana"] = "᩺",
	["Laoo"] = "຺",
	["Latn"] = "",
}

local sinh_cjct = {
	["ක‍්ව"] = "ක්‍ව", ["ත‍්ථ"] = "ත්‍ථ", ["ත‍්ව"] = "ත්‍ව",
	["න‍්ථ"] = "න්‍ථ", ["න‍්ද"] = "න්‍ද",  ["න‍්ධ"] = "න්‍ධ"
}

local nukta = u(0x09bc) -- Just list all those used here.

local variations = {
	["Mon"] = {
		["ဈ"] = "ၛ", ["ဤ"] = "ဣဳ", ["ဦ"] = "ဥု", ["ဧ"] = "ဨ", ["ီ"] = "ဳ", -- for IM fix below
		--Unicode doesn't have "great nya" so just leave ည္ည as is. (It looks like ည with one extra curve.)
	},
	["OldShan"] = {
		["က"] = "ၵ", ["ခ"] = "ၶ", ["ဂ"] = "ၷ", ["ဃ"] = "ꧠ", ["စ"] = "ၸ",
		["ဆ"] = "ꧡ", ["ဇ"] = "ၹ", ["ဈ"] = "ꧢ", ["ဉ"] = "ၺ", ["ည"] = "ၺ္ၺ", ["ဋ"] = "ꩦ",
		["ဌ"] = "ꩧ", ["ဍ"] = "ꩨ", ["ဎ"] = "ꩩ", ["ဏ"] = "ꧣ", ["ဒ"] = "ၻ",
		["ဓ"] = "ꩪ", ["န"] = "ၼ", ["ဖ"] = "ၽ", ["ဗ"] = "ၿ", ["ဘ"] = "ꧤ",
		["ဟ"] = "ႁ", ["ဠ"] = "ꩮ", ["အ"] = "ဢ", ["ဣ"] = "ဢိ", ["ဤ"] = "ဢီ",
		["ဥ"] = "ဢု", ["ဦ"] = "ဢူ", ["ဧ"] = "ဢေ", ["ဩ"] = "ဢေႃ", ["ါ"] = "ႃ", ["ာ"] = "ႃ",
		--Unicode doesn't have "Shan great sa" so just leave ဿ as is.
	},
	["NewShan"] = {
		--includes all Old Shan and the followings
		["ဿ"] = "သ်သ", ["္"] = "်",
	},
}

function export.show(frame)

	local args = frame:getParent().args

	local currentScriptCode = currentScript:getCode()
	local availableScripts = lang:getScripts()
	local thaiForm = args["Thai"] or currentScriptCode == "Thai" and PAGENAME or error("No Thai-script form detected.")
	local scriptCode

	local terms
	local first
	local output = Array('<div class="NavFrame" style="max-width:40em"><div class="NavHead" style="background:var(--wikt-palette-lightblue,#d9ebff);color:inherit">เขียนด้วยอักษรอื่น</div><div class="NavContent" style="text-align:left"><ul>')

	for _, script in ipairs(availableScripts) do
		scriptCode = script:getCode()
		terms = { args[scriptCode], args[scriptCode.."2"], args[scriptCode.."3"], args[scriptCode.."4"] }

		output:insert("<li>")

		local t1, t2, t3, t4
		t1 = export.conv(thaiForm, scriptCode, {}) -- not affect Thai itself

		if scriptCode == "Thai" or scriptCode == "Laoo" then
			t2 = export.mono_form(t1, scriptCode, {impl='no'})
		end

		if scriptCode == 'Laoo' then
			if not mw.ustring.find(t2, '[ຆຌຏຐຑຒຓຘຠຨຩ]') then
				t3 = mw.ustring.gsub(t2, 'ຍ', 'ຢ')
			end
		end

		if scriptCode == 'Mymr' then
			t2 = export.conv(thaiForm, scriptCode, {variation='1'}) --Mon
			t3 = export.conv(thaiForm, scriptCode, {variation='2'}) --Old Shan
			t4 = export.conv(thaiForm, scriptCode, {variation='3'}) --New Shan
		end

		if #terms == 0 then
			terms[1] = t1
			if t2 and (t1 ~= t2) then table.insert(terms, t2) end
			if t3 and (t1 ~= t3) and (t2 ~= t3) then table.insert(terms, t3) end
			if t4 and (t1 ~= t4) and (t2 ~= t4) and (t3 ~= t4) then table.insert(terms, t4) end
		elseif terms[1] ~= t1 and terms[2] ~= t1  and terms[3] ~= t1  and terms[4] ~= t1 then
			output:insert('[[Category:Pali terms with inconsistent transliterations]]')
		end

		if scriptCode ~= currentScriptCode or #terms > 1 then
			output:insert(labels.show_labels {
					lang = lang,
					labels = { script:getDisplayForm() },
				} .. ' ')
		end
		first = true
		for _, term in ipairs(terms) do
			if term ~= nil and term ~= PAGENAME then
				if first then
					output:insert(links.full_link({lang = lang, sc = script, term = term}))
					first = false
				else
					output:insert(" หรือ " .. links.full_link({lang = lang, sc = script, term = term}))
				end
			end
		end
		output:insert('</li>')

	end
	output:insert("</ul></div></div>")

	return output:concat()

end

--converts Thai to other scripts
function export.conv(text, script, options)

	if type(text) == "table" then
		options = {}
		options.impl = text.args["impl"]
		options.variation = text.args["variation"] --ID of variation: [Mymr: 1=Mon, 2=Old Shan, 3=New Shan]
		text, script = text.args[1], text.args[2]
	end
	if script == "Thai" then
		return text
	end
	if not s[script] then
		return nil
	end

	--text = mw.ustring.lower(text)
	text = gsub(text, "[0-9%.,%-]", s[script])
	text = gsub(text, "([เแไโ])([ก-ฮ])", "%2%1") --swap

	if script == "Latn" then
		text = gsub(text, "([กขคฆงจฉชฌญฏฐฑฒณตถทธนปผพภมยรลวสหฬ])$", "%1a")
		text = gsub(text, "([กขคฆงจฉชฌญฏฐฑฒณตถทธนปผพภมยรลวสหฬ])([%s%p])", "%1a%2")
		text = gsub(text, "([กขคฆงจฉชฌญฏฐฑฒณตถทธนปผพภมยรลวสหฬ])([กขคฆงจฉชฌญฏฐฑฒณตถทธนปผพภมยรลวสหฬํ])", "%1a%2")
		text = gsub(text, "([กขคฆงจฉชฌญฏฐฑฒณตถทธนปผพภมยรลวสหฬ])([กขคฆงจฉชฌญฏฐฑฒณตถทธนปผพภมยรลวสหฬํ])", "%1a%2") --twice
	end

	text = gsub(text, "[กขคฆงจฉชฌญฏฐฑฒณตถทธนปผพภมยรลวสหฬํ]", c[script])
	text = gsub(text, "อ[าิีุูเโ]?", iv[script])
	text = gsub(text, "[าิีุูเโ]", dv[script])

	text = gsub(text, "ฺ$", kill[script])
	text = gsub(text, "ฺ([%s%p])", kill[script] .. "%1")
	text = gsub(text, "ฺ", join[script])

	if script == "Mymr" then
		text = gsub(text, "င္", "င်္") -- Pali doesn't have -Vr mid-word like Sanskrit, so no need to include repha.
		text = gsub(text, "(င်္)([ဝခဂငဒပ])(ေ?)ာ", "%1%2%3ါ")
		text = gsub(text, "္[ယရ]", { ["္ယ"] = "ျ", ["္ရ"] = "ြ" }) --these not need tall aa
		text = gsub(text, "^([ဝခဂငဒပ])(ေ?)ာ", "%1%2ါ")
		text = gsub(text, "([^္])([ဝခဂငဒပ])(ေ?)ာ", "%1%2%3ါ")
		text = gsub(text, "([ဝခဂငဒပ])(္[က-အဿ])(ေ?)ာ", "%1%2%3ါ")
		text = gsub(text, "္[ဝဟ]", { ["္ဝ"] = "ွ", ["္ဟ"] = "ှ" })
		text = gsub(text, "ဉ္ဉ", "ည")
		text = gsub(text, "သ္သ", "ဿ")
		if options.variation == "1" then
			text = gsub(text, ".", variations.Mon)
			text = gsub(text, "ိံ", "ီ") --fix IM
		elseif options.variation == "2" then
			text = gsub(text, ".", variations.OldShan)
		elseif options.variation == "3" then
			text = gsub(text, ".", variations.OldShan)
			text = gsub(text, ".", variations.NewShan)
			text = gsub(text, "်".."်", "်") --fix nga
		end
	elseif script == "Lana" then
		text = gsub(text, "ᨦ᩠", "ᩘ")
		text = gsub(text, "^([ᨣᨴᨵᨷᩅ])(ᩮ?)ᩣ", "%1%2ᩤ")
		text = gsub(text, "([^᩠])([ᨣᨴᨵᨷᩅ])(ᩮ?)ᩣ", "%1%2%3ᩤ")
		text = gsub(text, "([ᨣᨴᨵᨷᩅ])(᩠[ᨠ-ᩌᩔ])(ᩮ?)ᩣ", "%1%2%3ᩤ")
		text = gsub(text, "᩠[ᩁᩃ]", { ["᩠ᩁ"] = "ᩕ", ["᩠ᩃ"] = "ᩖ" })
		text = gsub(text, "([ᨭ-ᨱ])᩠ᨮ", "%1ᩛ")
		text = gsub(text, "([ᨷ-ᨾ])᩠ᨻ", "%1ᩛ")
		text = gsub(text, "ᩈ᩠ᩈ", "ᩔ")
	elseif script == "Beng" then
		text = gsub(text, "ৰ্", "ৰ"..u(0x200d).."্") -- ৰ্(v-) needs ZWJ to display correctly
	elseif script == "Sinh" then
		local js = join["Sinh"]
		text = gsub(text, "("..js..")([යර])", u(0xdca, 0x200d).."%2")
		text = gsub(text,"[කතන]"..js.."[ථදධව]", sinh_cjct)
	elseif script == "Laoo" then
		text = gsub(text, "(.)([ເໂ])", "%2%1")
	end

	return text

end

--only applies to Thai and Lao
function export.mono_form(text, script)

	local result = text

	if script == "Thai" then
		result = gsub(result, "ํ", "งฺ")
		result = gsub(result, "([ก-ฮ])ฺ", "ั%1ฺ")
		result = gsub(result, "([ก-ฮ])([^ะัาิีฺุู])", "%1ะ%2")
		result = gsub(result, "([ก-ฮ])([^ะัาิีฺุู])", "%1ะ%2") --twice
		result = gsub(result, "([ก-ฮ])$", "%1ะ")
		result = gsub(result, "([ก-ฮ])([าิีฺุู])ั", "%1%2")
		result = gsub(result, "([เโ])([ก-ฮ])([ะั])", "%1%2")
		result = gsub(result, "^ั", "")
		result = gsub(result, "([%s%p])ั", "%1")
		result = gsub(result, "ฺ", "")
	elseif script == "Laoo" then
		result = gsub(result, "ໍ", "ງ຺")
		result = gsub(result, "([ກ-ຮ])຺", "ັ%1຺")
		result = gsub(result, "([ກ-ຮ])([^ະັາິີ຺ຸູ])", "%1ະ%2")
		result = gsub(result, "([ກ-ຮ])([^ະັາິີ຺ຸູ])", "%1ະ%2") --twice
		result = gsub(result, "([ກ-ຮ])$", "%1ະ")
		result = gsub(result, "([ກ-ຮ])([າິີ຺ຸູ])ັ", "%1%2")
		result = gsub(result, "([ເໂ])([ກ-ຮ])([ະັ])", "%1%2")
		result = gsub(result, "^ັ", "")
		result = gsub(result, "([%s%p])ັ", "%1")
		result = gsub(result, "຺", "")
	end
	
	return result

end

return export