Modulo:Parola cinese

La documentazione per questo modulo può essere creata in Modulo:Parola cinese/man

local p = {}

function p.categoriecomposti(frame) --funzione per le categorie dei composti dei caratteri
	sortpinyin = frame.args["sortpinyin"] --parametro "sortpinyin", passato dal template
--variabili interne al modulo:
	categoria_composti = ""
	hanzi = ""
	hanzi1 = ""; hanzi2 = ""; hanzi3 = ""; hanzi4 = ""; hanzi5 = ""; hanzi6 = ""; hanzi7 = ""; hanzi8 = ""; hanzi9 = ""; hanzi10 = ""
	--stringa categoria_composti; se il titolo della pagina contiene dei kanji, genera la categoria "composti di 'x' in giapponese"
		hanzi = (tostring(mw.title.getCurrentTitle())) --stringa "hanzi", corrisponde al titolo della pagina
		hanzi1 = mw.ustring.sub( hanzi, 1, 1 ) or ""; hanzi2 = mw.ustring.sub( hanzi, 2, 2 ) or ""; hanzi3 = mw.ustring.sub( hanzi, 3, 3 ) or ""; hanzi4 = mw.ustring.sub( hanzi, 4, 4 ) or ""; hanzi5 = mw.ustring.sub( hanzi, 5, 5 ) or ""; hanzi6 = mw.ustring.sub( hanzi, 6, 6 ) or ""; hanzi7 = mw.ustring.sub( hanzi, 7, 7 ) or ""; hanzi8 = mw.ustring.sub( hanzi, 8, 8 ) or ""; hanzi9 = mw.ustring.sub( hanzi, 9, 9 ) or ""; hanzi10 = mw.ustring.sub( hanzi, 10, 10 ) or ""; --scompone il titolo nei singoli caratteri che lo compongono (FUNZIONA PER COMPOSTI DI FINO A 10 CARATTERI; se ci dovessero essere parole più lunghe va aggiunto hanzi11... etc. proseguendo la numerazione, ma è un'eventualità talmente rara che si fa probabilmente prima a inserire manualmente le categorie mancanti nei lemmi)
			if hanzi1 == tostring(mw.title.getCurrentTitle()) then --se la parola è composta da un unico hanzi...
				categoria_composti_1 = p.cat("Composti di ".. hanzi1.. " in cinese| ") --genera la categoria lasciando uno spazio vuoto dopo il pipe, più elegante
				categoria_composti_2 = ""; categoria_composti_3 = ""; categoria_composti_4 = ""; categoria_composti_5 = ""; categoria_composti_6 = ""; categoria_composti_7 = ""; categoria_composti_8 = ""; categoria_composti_9 = ""; categoria_composti_10 = "" --...e le altre si annullano
			else --se la parola è composta da più di un solo hanzi, genera le categorie corrispondenti, mettendo il sortpinyin dopo il pipe
				if hanzi10 > "0" then
					categoria_composti_10 = p.cat("Composti di ".. hanzi10.. " in cinese|".. sortpinyin)
				else
					categoria_composti_10 = ""
				end
				if hanzi9 > "0" then
					categoria_composti_9 = p.cat("Composti di ".. hanzi9.. " in cinese|".. sortpinyin)
				else
					categoria_composti_9 = ""
				end
				if hanzi8 > "0" then
					categoria_composti_8 = p.cat("Composti di ".. hanzi8.. " in cinese|".. sortpinyin)
				else
					categoria_composti_8 = ""
				end
				if hanzi7 > "0" then
					categoria_composti_7 = p.cat("Composti di ".. hanzi7.. " in cinese|".. sortpinyin)
				else
					categoria_composti_7 = ""
				end
				if hanzi6 > "0" then
					categoria_composti_6 = p.cat("Composti di ".. hanzi6.. " in cinese|".. sortpinyin)
				else
					categoria_composti_6 = ""
				end
				if hanzi5 > "0" then
					categoria_composti_5 = p.cat("Composti di ".. hanzi5.. " in cinese|".. sortpinyin)
				else
					categoria_composti_5 = ""
				end
				if hanzi4 > "0" then
					categoria_composti_4 = p.cat("Composti di ".. hanzi4.. " in cinese|".. sortpinyin)
				else
					categoria_composti_4 = ""
				end
				if hanzi3 > "0" then
					categoria_composti_3 = p.cat("Composti di ".. hanzi3.. " in cinese|".. sortpinyin)
				else
					categoria_composti_3 = ""
				end
				if hanzi2 > "0" then
					categoria_composti_2 = p.cat("Composti di ".. hanzi2.. " in cinese|".. sortpinyin)
				else
					categoria_composti_2 = ""
				end
				if hanzi1 > "0" then
					categoria_composti_1 = p.cat("Composti di ".. hanzi1.. " in cinese|".. sortpinyin)
				else
					categoria_composti_1 = ""
				end
			end
			categoria_composti = categoria_composti_1.. categoria_composti_2.. categoria_composti_3.. categoria_composti_4.. categoria_composti_5.. categoria_composti_6.. categoria_composti_7.. categoria_composti_8.. categoria_composti_9.. categoria_composti_10 --genera la categoria per ciascuno dei composti della parola, se presenti, mettendo hiraganasort dopo il pipe
	return
	categoria_composti
	end
	
	-- questa funzione crea una categoria a partire dal o dai suoi argomenti
	function p.cat(x)
	return "[[Categoria:" .. x .. "]]"
	end

return p