มอดูล:lo-alt

จาก วิกิพจนานุกรม พจนานุกรมเสรี
local export = {}
local links = require("Module:links")
local gsub = mw.ustring.gsub

local lang = require("Module:languages").getByCode("lo")
local script = require("Module:scripts").getByCode("Laoo")
local PAGENAME = mw.title.getCurrentTitle().text

local conCls1 = "[ກ-ຮໜໝ]"
local conCls2 = "ຫ[ງຍນມຣລວຼ]"
local toneCls = "[່້໊໋]?"

-- This must be imperfect since ຍ could appear at any position.
local datedSeq = {
	["(ເ"..conCls1.."ີ"..toneCls..")ຍ"] = "%1ຽ", -- oey
	["(ເ"..conCls2.."ີ"..toneCls..")ຍ"] = "%1ຽ",
	["("..conCls1..toneCls.."[ວອາ])ຍ"] = "%1ຽ", -- uay, oay, aay
	["("..conCls2..toneCls.."[ວອາ])ຍ"] = "%1ຽ",
	["("..conCls1.."[ຶືຸູ]"..toneCls..")ຍ"] = "%1ຽ", -- uey, uuey, uy, uuy
	["("..conCls2.."[ຶືຸູ]"..toneCls..")ຍ"] = "%1ຽ",
	["ໜ"] = "ຫນ",
	["ໝ"] = "ຫມ",
	["ຫຼ"] = "ຫລ",
}

local function preloadDatedForm()

	local pdated = PAGENAME

	for k, v in pairs(datedSeq) do
		pdated = gsub(pdated, k, v)
	end

	return (pdated ~= PAGENAME and pdated or nil)

end

function export.show(frame)

	local args = frame:getParent().args
	local common = args["c"] or args["common"] or nil
	local dated = args["d"] or args["dated"] or preloadDatedForm()
	local obsolete = args["o"] or args["obs"] or args["obsolete"] or nil

	local altForms = {}
	altForms.common = (common and mw.text.split(common, ",", true) or {})
	altForms.dated = (dated and mw.text.split(dated, ",", true) or {})
	altForms.obsolete = (obsolete and mw.text.split(obsolete, ",", true) or {})

	local output = {}

	if common then
		table.insert(altForms.common, 1, "lo")
		table.insert(output, "* " .. frame:expandTemplate{title = "alter", args = altForms.common})
	end
	if dated then
		table.insert(altForms.dated, 1, "lo")
		table.insert(altForms.dated, "")
		table.insert(altForms.dated, "ล้าสมัย")
		table.insert(output, "* " .. frame:expandTemplate{title = "alter", args = altForms.dated})
	end
	if obsolete then
		table.insert(altForms.obsolete, 1, "lo")
		table.insert(altForms.obsolete, "")
		table.insert(altForms.obsolete, "เลิกใช้")
		table.insert(output, "* " .. frame:expandTemplate{title = "alter", args = altForms.obsolete})
	end

	return table.concat(output, "\n")

end

return export