Module:syllables: Difference between revisions

From Laenkea
Jump to navigation Jump to search
No edit summary
mNo edit summary
 
(5 intermediate revisions by the same user not shown)
Line 7: Line 7:
[2] = {list = true, allow_empty = true},
[2] = {list = true, allow_empty = true},
["caption"] = {},
["caption"] = {},
["delimiter"] = {},
}
}


function export.make_syllables(language, caption, list)
function export.make_syllables(language, caption, delimiter, list)
local syllables = ""
local syllables = ""
local i = 1
local i = 1
local n_i = 1
local n_i = 1
while list[i] do
while list[i] do
if list[i] == "" then
if list[i] == "" then
Line 18: Line 20:
n_i = 1
n_i = 1
else
else
if n_i > 1 then syllables = syllables .. "·" end
if n_i > 1 then syllables = syllables .. delimiter end
syllables = syllables .. list[i]
syllables = syllables .. list[i]
n_i = n_i + 1
n_i = n_i + 1
Line 29: Line 31:
function export.show_syllables(frame)
function export.show_syllables(frame)
local args = m_parameters.process(frame:getParent().args, params)
local args = m_parameters.process(frame:getParent().args, params)
return export.make_syllables(m_languages.get_by_code(args[1]), args["caption"] or "Syllabification", args[2])
return export.make_syllables(m_languages.get_by_code(args[1]), args["caption"] or "Syllabification", args["delimiter"] or "·", args[2])
end
end


function export.show_hyphens(frame)
function export.show_hyphens(frame)
local args = m_parameters.process(frame:getParent().args, params)
local args = m_parameters.process(frame:getParent().args, params)
return export.make_syllables(m_languages.get_by_code(args[1]), args["caption"] or "Hyphenation", args[2])
return export.make_syllables(m_languages.get_by_code(args[1]), args["caption"] or "Hyphenation", args["delimiter"] or "·", args[2])
end
end


return export
return export

Latest revision as of 18:35, 24 August 2023

Documentation for this module may be created at Module:syllables/documentation

local export = {}

local m_languages = require("Module:languages")
local m_parameters = require("Module:parameters")
local params = {
	[1] = {required = true},
	[2] = {list = true, allow_empty = true},
	["caption"] = {},
	["delimiter"] = {},
}

function export.make_syllables(language, caption, delimiter, list)
	local syllables = ""
	local i = 1
	local n_i = 1
	
	while list[i] do
		if list[i] == "" then
			syllables = syllables .. ", "
			n_i = 1
		else
			if n_i > 1 then syllables = syllables .. delimiter end
			syllables = syllables .. list[i]
			n_i = n_i + 1
		end
		i = i + 1
	end
	return caption .. ': <span style="font-size:110%;">' .. syllables .. '</span>'
end

function export.show_syllables(frame)
	local args = m_parameters.process(frame:getParent().args, params)
	return export.make_syllables(m_languages.get_by_code(args[1]), args["caption"] or "Syllabification", args["delimiter"] or "·", args[2])
end

function export.show_hyphens(frame)
	local args = m_parameters.process(frame:getParent().args, params)
	return export.make_syllables(m_languages.get_by_code(args[1]), args["caption"] or "Hyphenation", args["delimiter"] or "·", args[2])
end

return export