Jump to content

Module:Hyphenation

Frae Wikipedia, the free beuk o knawledge
local export = {}

local categorise_syllables = {
	["es"] = true,
	["fr"] = true,
	["it"] = true,
	["pt"] = true,
}

function export.hyphenation(frame)
	local parent_args = frame:getParent().args
	local compat = parent_args["lang"]
	local offset = compat and 0 or 1
	local params = {
		[compat and "lang" or 1] = {required = true, default = "und"},
		[1 + offset] = {list = true, required = true, default = "{{{2}}}"},
		
		["caption"] = {},
		["nocaption"] = {type = "boolean"},
		["sc"] = {},
	}
	
	local args = require("Module:parameters").process(parent_args, params)
	
	local lang = args[compat and "lang" or 1]
	local lang = require("Module:languages").getByCode(lang) or error("The language code \"" .. lang .. "\" is not valid.")
	local sc = args["sc"] and (require("Module:scripts").getByCode(args["sc"]) or error("The script code \"" .. sc .. "\" is not valid.")) or nil
	
	local text = require("Module:links").full_link({lang = lang, sc = sc, alt = table.concat(args[1 + offset], "‧"), tr = "-"})
	local category = ""
	
	if categorise_syllables[lang:getCode()] then
		category = require("Module:utilities").format_categories({lang:getCanonicalName() .. " " .. tostring(#args[1 + offset]) .. "-syllable words"}, lang)
	end
	
	return (args["nocaption"] and "" or (args["caption"] or "Hyphenation") .. ": ") .. text .. category
end

return export