Jump to content

Module:pi-alt

ពីWiktionary

Documentation for this module may be created at Module:pi-alt/doc

-- 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 = scripts.findBestScript(PAGENAME, lang)

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

-- whatever ordering
local c = {
	["Deva"] = {
		["ក"] = "क", ["ខ"] = "ख", ["គ"] = "ग", ["ឃ"] = "घ", ["ង"] = "ङ",
		["ច"] = "च", ["ឆ"] = "छ", ["ជ"] = "ज", ["ឈ"] = "झ", ["ញ"] = "ञ",
		["ដ"] = "ट", ["ឋ"] = "ठ", ["ឌ"] = "ड", ["ឍ"] = "ढ", ["ណ"] = "ण",
		["ត"] = "त", ["ថ"] = "थ", ["ទ"] = "द", ["ធ"] = "ध", ["ន"] = "न",
		["ប"] = "प", ["ផ"] = "फ", ["ព"] = "ब", ["ភ"] = "भ", ["ម"] = "म",
		["យ"] = "य", ["រ"] = "र", ["ល"] = "ल", ["វ"] = "व", ["ស"] = "स",
		["ហ"] = "ह", ["ឡ"] = "ळ",
		["ំ"] = "ं",
		[""] = "",
	},
	["Beng"] = {
		["ក"] = "ক", ["ខ"] = "খ", ["គ"] = "গ", ["ឃ"] = "ঘ", ["ង"] = "ঙ",
		["ច"] = "চ", ["ឆ"] = "ছ", ["ជ"] = "জ", ["ឈ"] = "ঝ", ["ញ"] = "ঞ",
		["ដ"] = "ট", ["ឋ"] = "ঠ", ["ឌ"] = "ড", ["ឍ"] = "ঢ", ["ណ"] = "ণ",
		["ត"] = "ত", ["ថ"] = "থ", ["ទ"] = "দ", ["ធ"] = "ধ", ["ន"] = "ন",
		["ប"] = "প", ["ផ"] = "ফ", ["ព"] = "ব", ["ភ"] = "ভ", ["ម"] = "ম",
		["យ"] = "য", ["រ"] = "র", ["ល"] = "ল", ["វ"] = "ৰ", ["ស"] = "স",
		["ហ"] = "হ", ["ឡ"] = "ল়",
		["ំ"] = "ং",
		[""] = "",
	},
	["Brah"] = {
		["ក"] = "𑀓", ["ខ"] = "𑀔", ["គ"] = "𑀕", ["ឃ"] = "𑀖", ["ង"] = "𑀗",
		["ច"] = "𑀘", ["ឆ"] = "𑀙", ["ជ"] = "𑀚", ["ឈ"] = "𑀛", ["ញ"] = "𑀜",
		["ដ"] = "𑀝", ["ឋ"] = "𑀞", ["ឌ"] = "𑀟", ["ឍ"] = "𑀠", ["ណ"] = "𑀡",
		["ត"] = "𑀢", ["ថ"] = "𑀣", ["ទ"] = "𑀤", ["ធ"] = "𑀥", ["ន"] = "𑀦",
		["ប"] = "𑀧", ["ផ"] = "𑀨", ["ព"] = "𑀩", ["ភ"] = "𑀪", ["ម"] = "𑀫",
		["យ"] = "𑀬", ["រ"] = "𑀭", ["ល"] = "𑀮", ["វ"] = "𑀯", ["ស"] = "𑀲",
		["ហ"] = "𑀳", ["ឡ"] = "𑀴",
		["ំ"] = "𑀁",
		[""] = "",
	},
	["Thai"] = {
		["ក"] = "ก", ["ខ"] = "ข", ["គ"] = "ค", ["ឃ"] = "ฆ", ["ង"] = "ง",
		["ច"] = "จ", ["ឆ"] = "ฉ", ["ជ"] = "ช", ["ឈ"] = "ฌ", ["ញ"] = "ญ",
		["ដ"] = "ฏ", ["ឋ"] = "ฐ", ["ឌ"] = "ฑ", ["ឍ"] = "ฒ", ["ណ"] = "ณ",
		["ត"] = "ต", ["ថ"] = "ถ", ["ទ"] = "ท", ["ធ"] = "ธ", ["ន"] = "น",
		["ប"] = "ป", ["ផ"] = "ผ", ["ព"] = "พ", ["ភ"] = "ภ", ["ម"] = "ม",
		["យ"] = "ย", ["រ"] = "ร", ["ល"] = "ล", ["វ"] = "ว", ["ស"] = "ส",
		["ហ"] = "ห", ["ឡ"] = "ฬ",
		["ំ"] = "ํ",
		[""] = "",
	},
	["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"] = {
		["អ"] = "𑀅", ["អា"] = "𑀆",
		["ឥ"] = "𑀇", ["ឦ"] = "𑀈",
		["ឧ"] = "𑀉", ["ឩ"] = "𑀊",
		["ឯ"] = "𑀏",
		["ឱ"] = "𑀑",
	},
	["Thai"] = {
		["អ"] = "อ", ["អា"] = "อา",
		["ឥ"] = "อิ", ["ឦ"] = "อี",
		["ឧ"] = "อุ", ["ឩ"] = "อู",
		["ឯ"] = "อเ",
		["ឱ"] = "อโ",
	},
	["Mymr"] = {
		["អ"] = "အ", ["អា"] = "အာ",
		["ឥ"] = "ဣ", ["ឦ"] = "ဤ",
		["ឧ"] = "ဥ", ["ឩ"] = "ဦ",
		["ឯ"] = "ဧ",
		["ឱ"] = "ဩ",
	},
	["Sinh"] = {
		["អ"] = "අ", ["អា"] = "ආ",
		["ឥ"] = "ඉ", ["ឦ"] = "ඊ",
		["ឧ"] = "උ", ["ឩ"] = "ඌ",
		["ឯ"] = "එ",
		["ឱ"] = "ඔ",
	},
	["Lana"] = {
		["អ"] = "ᩋ", ["អា"] = "ᩋᩣ",
		["ឥ"] = "ᩍ", ["ឦ"] = "ᩎ",
		["ឧ"] = "ᩏ", ["ឩ"] = "ᩐ",
		["ឯ"] = "ᩑ",
		["ឱ"] = "ᩋᩰ",
	},
	["Laoo"] = {
		["អ"] = "ອ", ["អា"] = "ອາ",
		["ឥ"] = "ອິ", ["ឦ"] = "ອີ",
		["ឧ"] = "ອຸ", ["ឩ"] = "ອູ",
		["ឯ"] = "ອເ",
		["ឱ"] = "ອໂ",
	},
	["Latn"] = {
		["អ"] = "a", ["អា"] = "ā",
		["ឥ"] = "i", ["ឦ"] = "ī",
		["ឧ"] = "u", ["ឩ"] = "ū",
		["ឯ"] = "e",
		["ឱ"] = "o",
	},
}

local dv = {
	["Deva"] = {
		[""] = "", ["ា"] = "ा",
		["ិ"] = "ि", ["ី"] = "ी",
		["ុ"] = "ु", ["ូ"] = "ू",
		["េ"] = "े",
		["ោ"] = "ो",
	},
	["Beng"] = {
		[""] = "", ["ា"] = "া",
		["ិ"] = "ি", ["ី"] = "ী",
		["ុ"] = "ু", ["ូ"] = "ূ",
		["េ"] = "ে",
		["ោ"] = "ো",
	},
	["Brah"] = {
		[""] = "", ["ា"] = "𑀸",
		["ិ"] = "𑀺", ["ី"] = "𑀻",
		["ុ"] = "𑀼", ["ូ"] = "𑀽",
		["េ"] = "𑁂",
		["ោ"] = "𑁄",
	},
	["Thai"] = {
		[""] = "", ["ា"] = "า",
		["ិ"] = "ิ", ["ី"] = "ี",
		["ុ"] = "ุ", ["ូ"] = "ู",
		["េ"] = "เ",
		["ោ"] = "โ",
	},
	["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"] = "𑁯",
		["."] = "𑁈", [","] = "𑁇", ["-"] = "-",
	},
	["Thai"] = {
		["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"] = "𑁆",
	["Thai"] = "ฺ",
	["Mymr"] = "္",
	["Sinh"] = u(0x200d, 0x0dca),
	["Lana"] = "᩠",
	["Laoo"] = "຺",
	["Latn"] = "",
}

local kill = {
	["Deva"] = "्",
	["Beng"] = "্",
	["Brah"] = "𑁆",
	["Thai"] = "ฺ",
	["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 khmrForm = args["Khmr"] or currentScriptCode == "Khmr" and PAGENAME or error("No Khmer-script form detected.")
	local scriptCode

	local terms
	local first
	local output = Array('<div class="NavFrame" style="max-width:40em"><div class="NavHead" style="background:#f9f9f9">សរសេរជាមួយអក្សរផ្សេង</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(Form, scriptCode, {}) -- not affect Khmer itself

		if scriptCode == "Khmr" 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(khmrForm, scriptCode, {variation='1'}) --Mon
			t3 = export.conv(khmrForm, scriptCode, {variation='2'}) --Old Shan
			t4 = export.conv(khmrForm, 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({ script:getCategoryName() }, lang) .. ' ')
		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 Khmr 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 == "Khmr" 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, "င္", "င်္")
		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