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

ผลต่างระหว่างรุ่นของ "มอดูล:hyphenation"

จาก วิกิพจนานุกรม พจนานุกรมเสรี
เนื้อหาที่ลบ เนื้อหาที่เพิ่ม
ZilentFyld (คุย | ส่วนร่วม)
ไม่มีความย่อการแก้ไข
ไม่มีความย่อการแก้ไข
 
(ไม่แสดง 6 รุ่นระหว่างกลางโดยผู้ใช้ 2 คน)
บรรทัดที่ 4: บรรทัดที่ 4:
["es"] = true,
["es"] = true,
["fr"] = true,
["fr"] = true,
["it"] = true,
["pt"] = true,
["pt"] = true,
}
}



function export.hyphenation(frame)
--[=[
Meant to be called from a module. `data` is a table containing the following fields:

{
lang = LANGUAGE_OBJECT,
hyphs = {{hyph = {"SYL", "SYL", ...}, qualifiers = nil or {"QUALIFIER", "QUALIFIER", ...}}, ...},
sc = nil or SCRIPT_OBJECT,
caption = nil or "CAPTION",
nocaption = BOOLEAN,
}

Here:

* `lang` is a language object.
* `hyphs` is the list of hyphenations to display. SYL is a syllable. QUALIFIER is a qualifier string to display before
the specific hyphenation in question, formatted using format_qualifier() in [[Module:qualifier]].
* `sc`, if specified, is a script object.
* `caption`, if specified, overrides the default caption "Hyphenation". A colon and space is automatically added after
the caption.
* `nocaption`, if specified, suppresses the caption entirely.
]=]
function export.format_hyphenations(data)
local hyphtexts = {}
local hyphcats = {}

for _, hyph in ipairs(data.hyphs) do
if #hyph.hyph == 0 then
error("Saw empty hyphenation; use || to separate hyphenations")
end
local text = require("Module:links").full_link {
lang = data.lang, sc = data.sc, alt = table.concat(hyph.hyph, "‧"), tr = "-" }
if hyph.qualifiers and hyph.qualifiers[1] then
text = require("Module:qualifier").format_qualifier(hyph.qualifiers) .. " " .. text
end
table.insert(hyphtexts, text)
if categorise_syllables[data.lang:getCode()] then
--table.insert(hyphcats, data.lang:getCanonicalName() .. " " .. tostring(#hyph.hyph) .. "-syllable words")
table.insert(hyphcats, "ศัพท์" .. data.lang:getCategoryName() .. "ที่มี " .. tostring(#hyph.hyph) .. " พยางค์")
end
end

local text = table.concat(hyphtexts, ", ")
local categories = #hyphcats > 0 and require("Module:utilities").format_categories(hyphcats, data.lang) or ""
return (data.nocaption and "" or (data.caption or "การแบ่งพยางค์") .. ": ") .. text .. categories
end


-- The implementation of the {{hyphenation}} template. Broken out so that it can function as an (older) entry point
-- for modules. FIXME: Convert modules that use this to use format_hyphenations() directly.
function export.hyphenate(parent_args)
local compat = parent_args["lang"]
local offset = compat and 0 or 1
local params = {
local params = {
[1] = {list = true, required = true, default = "{{{1}}}"},
[compat and "lang" or 1] = {required = true, default = "und"},
[1 + offset] = {list = true, required = true, allow_holes = true, default = "{{{2}}}"},
["q"] = {list = true, allow_holes = true},
["caption"] = {},
["caption"] = {},
["lang"] = {required = true, default = "und"},
["nocaption"] = {type = "boolean"},
["nocaption"] = {type = "boolean"},
["sc"] = {},
["sc"] = {},
}
}
local args = require("Module:parameters").process(parent_args, params)
local args = require("Module:parameters").process(frame:getParent().args, params)
local lang = require("Module:languages").getByCode(args[compat and "lang" or 1], compat and "lang" or 1)
local sc = args["sc"] and require("Module:scripts").getByCode(args["sc"], "sc") or nil

local lang = require("Module:languages").getByCode(args["lang"]) or error("The language code \"" .. args["lang"] .. "\" is not valid.")
local data = {
local sc = args["sc"] and (require("Module:scripts").getByCode(args["sc"]) or error("The script code \"" .. sc .. "\" is not valid.")) or nil
lang = lang,
sc = sc,
local text = require("Module:links").full_link({lang = lang, sc = sc, alt = table.concat(args[1], "‧"), tr = "-"})
hyphs = {},
local category = ""
caption = args.caption,
nocaption = args.nocaption,
if categorise_syllables[lang:getCode()] then
}
category = require("Module:utilities").format_categories({"ศัพท์ภาษา" .. lang:getCanonicalName() .. "ที่มี" .. tostring(#args[1]) .. "พยางค์"}, lang)
local this_hyph = {hyph = {}}
local maxindex = args[1 + offset].maxindex
local function insert_hyph()
local hyphnum = #data.hyphs + 1
if args["q"][hyphnum] then
this_hyph.qualifiers = {args["q"][hyphnum]}
end
table.insert(data.hyphs, this_hyph)
end
end
for i=1, maxindex do
local syl = args[1 + offset][i]
return (args["nocaption"] and "" or (args["caption"] or "การแบ่งพยางค์") .. ": ") .. text .. category
if not syl then
insert_hyph()
this_hyph = {hyph = {}}
else
table.insert(this_hyph.hyph, syl)
end
end
insert_hyph()

return export.format_hyphenations(data)
end
end


-- Entry point for {{hyphenation}} template.
function export.hyphenation(frame)
local parent_args = frame:getParent().args
return export.hyphenate(parent_args)
end



return export
return export

รุ่นแก้ไขปัจจุบันเมื่อ 14:22, 9 มีนาคม 2565

This module implements {{hyphenation}}.


local export = {}

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


--[=[
Meant to be called from a module. `data` is a table containing the following fields:

{
  lang = LANGUAGE_OBJECT,
  hyphs = {{hyph = {"SYL", "SYL", ...}, qualifiers = nil or {"QUALIFIER", "QUALIFIER", ...}}, ...},
  sc = nil or SCRIPT_OBJECT,
  caption = nil or "CAPTION",
  nocaption = BOOLEAN,
}

Here:

* `lang` is a language object.
* `hyphs` is the list of hyphenations to display. SYL is a syllable. QUALIFIER is a qualifier string to display before
  the specific hyphenation in question, formatted using format_qualifier() in [[Module:qualifier]].
* `sc`, if specified, is a script object.
* `caption`, if specified, overrides the default caption "Hyphenation". A colon and space is automatically added after
  the caption.
* `nocaption`, if specified, suppresses the caption entirely.
]=]
function export.format_hyphenations(data)
	local hyphtexts = {}
	local hyphcats = {}

	for _, hyph in ipairs(data.hyphs) do
		if #hyph.hyph == 0 then
			error("Saw empty hyphenation; use || to separate hyphenations")
		end
		local text = require("Module:links").full_link {
			lang = data.lang, sc = data.sc, alt = table.concat(hyph.hyph, "‧"), tr = "-" }
		if hyph.qualifiers and hyph.qualifiers[1] then
			text = require("Module:qualifier").format_qualifier(hyph.qualifiers) .. " " .. text
		end
		table.insert(hyphtexts, text)
		if categorise_syllables[data.lang:getCode()] then
			--table.insert(hyphcats, data.lang:getCanonicalName() .. " " .. tostring(#hyph.hyph) .. "-syllable words")
			table.insert(hyphcats, "ศัพท์" .. data.lang:getCategoryName() .. "ที่มี " .. tostring(#hyph.hyph) .. " พยางค์")
		end
	end

	local text = table.concat(hyphtexts, ", ")
	local categories = #hyphcats > 0 and require("Module:utilities").format_categories(hyphcats, data.lang) or ""
	return (data.nocaption and "" or (data.caption or "การแบ่งพยางค์") .. ": ") .. text .. categories
end


-- The implementation of the {{hyphenation}} template. Broken out so that it can function as an (older) entry point
-- for modules. FIXME: Convert modules that use this to use format_hyphenations() directly.
function export.hyphenate(parent_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, allow_holes = true, default = "{{{2}}}"},
		["q"] = {list = true, allow_holes = true},
		["caption"] = {},
		["nocaption"] = {type = "boolean"},
		["sc"] = {},
	}
	local args = require("Module:parameters").process(parent_args, params)
	
	local lang = require("Module:languages").getByCode(args[compat and "lang" or 1], compat and "lang" or 1)
	local sc = args["sc"] and require("Module:scripts").getByCode(args["sc"], "sc") or nil

	local data = {
		lang = lang,
		sc = sc,
		hyphs = {},
		caption = args.caption,
		nocaption = args.nocaption,
	}
	local this_hyph = {hyph = {}}
	local maxindex = args[1 + offset].maxindex
	local function insert_hyph()
		local hyphnum = #data.hyphs + 1
		if args["q"][hyphnum] then
			this_hyph.qualifiers = {args["q"][hyphnum]}
		end
		table.insert(data.hyphs, this_hyph)
	end
	for i=1, maxindex do
		local syl = args[1 + offset][i]
		if not syl then
			insert_hyph()
			this_hyph = {hyph = {}}
		else
			table.insert(this_hyph.hyph, syl)
		end
	end
	insert_hyph()

	return export.format_hyphenations(data)
end


-- Entry point for {{hyphenation}} template.
function export.hyphenation(frame)
	local parent_args = frame:getParent().args
	return export.hyphenate(parent_args)
end


return export