Module:User:Suzukaze-c/zh-forms

Hello, you have come here looking for the meaning of the word Module:User:Suzukaze-c/zh-forms. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:User:Suzukaze-c/zh-forms, but we will also tell you about its etymology, its characteristics and you will know how to say Module:User:Suzukaze-c/zh-forms in singular and plural. Everything you need to know about the word Module:User:Suzukaze-c/zh-forms you have here. The definition of the word Module:User:Suzukaze-c/zh-forms will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:User:Suzukaze-c/zh-forms, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

This is a private module sandbox of Suzukaze-c, for their own experimentation. Items in this module may be added and removed at Suzukaze-c's discretion; do not rely on this module's stability.


local export = {}
local m_zh = require("Module:zh")
local links = require("Module:links")
local lang = require("Module:languages")
local find = mw.ustring.find
local gsub = mw.ustring.gsub
local match = mw.ustring.match
local len = mw.ustring.len

function is_left(length, var_count)
	return (length > 3 or var_count * length > 5)
end
	
function insert_st(set, text)
	if find(text, "^ ") or find(text, " $") then
		error("Please remove the leading and / or trailing space(s) in the 's' and 't' parameters.")
	end
	table.insert(set, text)
end

function add_template_styles_tag(frame)
	return frame:extensionTag("templatestyles", "", { src = "Template:sandbox/styles.css" } )
end

function calculate_word_division(comp_type, t, length)
	local test_word = t
	local word_division = {}
	local decomposable = false
	local i = 1

	if comp_type then
		for index in mw.text.gsplit(comp_type, "", true) do
			if find(mw.ustring.sub(test_word, i, i), '') then
				table.insert(word_division, { i, i } )
				i = i + 1
			elseif mw.ustring.sub(test_word, i, i) == '…' then
				table.insert(word_division, { i, i + 1 } )
				i = i + 2
			end
			table.insert(word_division, { i, i + index - 1 } )
			i = i + index
		end
		if i - 1 ~= len(gsub(test_word, '…+$', '')) and not find(table.concat(t) .. table.concat(s), "") then
			error("'type' parameter does not match word length.")
		end
	else
		for i = 1, length do
			table.insert(word_division, { i, i } )
		end
		decomposable = len(gsub(test_word, '…+$', '')) > 2 and true or false
	end

	return decomposable, word_division
end

function calculate_char_set(identity, word_division, char_set)
	for _, id in ipairs(identity) do
		for i, position in ipairs(word_division) do
			local char_string = ""
			for j = 1, #id do
				local word_form = mw.ustring.sub(id, position, position)
				if not find(char_string, word_form) then
					char_string = (char_string ~= "" and (char_string .. '/') or "") .. word_form
				end
			end
			if not find(char_string, '') then
				local hash = {}
				for thing in mw.text.gsplit(char_string, (delink and "" or "/")) do
					table.insert(hash, links.language_link({ lang = lang.getByCode("zh"), term = thing }) .. asterisk(thing, true))
				end
				char_string = table.concat(hash, (delink and "" or "/"))
			end
			table.insert(char_set, char_string)
		end
		for _, item in ipairs(id) do
			if not (mw.title.new(item) or {}).exists and item ~= mw.title.getCurrentTitle().subpageText then
				table.insert(uncreated, '"]"')
			end
		end
	end

	return char_set
end

function export.make(frame)
	local params = {
		 = { list = true, allow_holes = true, allow_empty = true },
		 = { list = true },
		 = { list = true },
		 = {},  = {},  = {},  = {},  = {},  = {}
	}
	local args = require("Module:parameters").process(frame:getParent().args, params)

	local identity = {}
	identity.simp = {}
	identity.trad = {}

	if not args then
		table.insert(identity.trad, 1, mw.title.getCurrentTitle().subpageText)
	end
	for i = 1, #args do insert_st(identity.simp, args) end
	for i = 1, #args do insert_st(identity.trad, args) end
	if #identity.trad ~= 1 and #identity.simp == 0 then
		table.insert(identity.simp, identity.trad)
	end

	local test_word = identity.trad
	local length = len(test_word)
	local decomposable, word_division

	decomposable, word_division = calculate_word_division(args, identity.trad, length)

	local char_set = {}
	char_set.simp = {}
	char_set.trad = {}

	char_set = calculate_char_set(identity, word_division, char_set)

	local el_table = mw.html.create("table")
		:addClass("zhForms")
		:addClass(is_left(length, math.max(#identity.trad, #identity.simp)) and "zhForms--left" or nil)
	:done()

	local el_glosses = mw.html.create("tr")
		:addClass("zhForms__glosses")
		:tag("td")
		:done()
	:done()
	if args then
		if args == "-" then
			el_glosses
				:tag("th")
					:addClass("zhForms__gloss")
					:attr("colspan", length)
					:wikitext("<i>phonetic</i>")
				:done()
			:done()
		elseif length == "1" then
		else
		end
	end

	el_table
		:node(el_glosses)
	:done()

	return tostring(el_table) .. add_template_styles_tag(frame)
end

return export