Модуль:ja-compound

Wiktionary дан

Documentation for this module may be created at Модуль:ja-compound/doc

local export = {}

local m_ja = require("Module:ja")
local m_links = require("Module:links")
local lang = require("Module:languages").getByCode("ja")
local sc = require("Module:scripts").getByCode("Jpan")

function export.show(frame)
	local params = {
		[1] = {list = true, allow_holes = true},
		["t"] = {list = true, allow_holes = true},
		["rom"] = {list = true, allow_holes = true},
		["pos"] = {list = true, allow_holes = true},
		["lit"] = {list = true, allow_holes = true},
		["linkto"] = {list = true, allow_holes = true},
		["sort"] = {},
		["nocat"] = {},
	}
	local args = require("Module:parameters").process(frame:getParent().args, params)
	local len = (args[1].maxindex + 1) / 2
	local result = {}
	local sort = ""
	local term, alt, tr, gloss, pos, lit
	for i=1,len do
		term = args["linkto"][i] or mw.ustring.gsub(args[1][2*i-1] or "", "[%% ]", "")
		alt = (args[1][2*i-1] and args[1][2*i]) and m_ja.add_ruby_backend(args[1][2*i-1], args[1][2*i]) or (args[1][2*i-1] or args[1][2*i])
		tr = args["rom"][i] or m_ja.kana_to_romaji(args[1][2*i] or args[1][2*i-1])
		gloss = args["t"][i]
		pos = args["pos"][i]
		lit = args["lit"][i]
		if term == "" then term = nil end
		table.insert(result, m_links.full_link({lang = lang, sc = sc, term = term, alt = alt, tr = tr, gloss = gloss, pos = pos, lit = lit}, "term"))
		sort = sort .. mw.ustring.gsub(args[1][2*i] or args[1][2*i-1], "[%^%-%% ]", "")
	end
	return table.concat(result, " + ") .. (args["nocat"] and "" or ("[[Category:Japanese compound words|" .. (args["sort"] or sort) .. "]]"))
end

return export