モジュール:labels/templates

出典: フリー多機能辞典『ウィクショナリー日本語版(Wiktionary)』
ナビゲーションに移動 検索に移動

このモジュールについての説明文ページを モジュール:labels/templates/doc に作成できます

local m_labels = require("モジュール:labels")

local export = {}

function export.show(frame)
	local compat = (frame.args["compat"] or "") ~= ""
	local term_mode = (frame.args["term"] or "") ~= ""
	
	local params = {
		[1] = {required = true},
		[2] = {list = true},
		["nocat"] = {type = "boolean"},
		["script"] = {},
		["script2"] = {},
		["sort"] = {},
		["sort2"] = {},
	}
	
	if compat then
		params[1] = params[2]
		params[2] = nil
		params["lang"] = {required = true}
	end
	
	local args = require("モジュール:parameters").process(frame:getParent().args, params)
	
	-- Gather parameters
	local lang = args[compat and "lang" or 1]
	local labels = args[compat and 1 or 2]
	local nocat = args["nocat"]
	local script = args["script"]
	local script2 = args["script2"]
	local sort_key = args["sort"]
	local sort_key2 = args["sort2"]

	if not lang then
		if mw.title.getCurrentTitle().nsText == "テンプレート" then
			lang = "und"
		else
			error("言語コードが指定されていません。第1パラメータを用いてテンプレートにコードを与えて下さい。")
		end
	end
	
	lang = require("モジュール:languages").getByCode(lang) or error("言語コード \"" .. lang .. "\" は無効です。")
	
	return m_labels.show_labels(labels, lang, script, script2, sort_key, sort_key2, nocat, term_mode)
end

-- temporary. intentionally undocumented.
-- this function is only to be used in {{alternative spelling of}}, {{eye dialect of}} and similar templates
function export.show_from(frame)
	local m_labeldata = require('モジュール:labels/data')
	
	local froms = {}
	local args = frame:getParent().args
	local nocat = args["nocat"]
	local lang = args["lang"] or "en"
	local limit = frame.args.limit and tonumber(frame.args.limit) or 99999
	
	lang = require("モジュール:languages").getByCode(lang) or error("言語コード \"" .. lang .. "\" は無効です。")

	local key, i = 'from', 1
	while args[key] do
		local k = args[key]
		k = m_labeldata.aliases[k] or k
		local data = m_labeldata.labels[k]
		local label = data and data.display or k
		
		if not nocat and data then
			if data.regional_categories then
				for j, cat in ipairs(data.regional_categories) do
					label = label .. '[[カテゴリ:' .. cat .. ' ' .. lang:getCanonicalName() .. ']]'	
				end
			end
		
			if data.plain_categories then
				for j, cat in ipairs(data.plain_categories) do
					label = label .. '[[カテゴリ:' .. cat .. ']]'	
				end
			end
		end

		table.insert(froms, label)
		i = i + 1
		if i > limit then
			break	
		end
		key = 'from' .. i
	end
	
	if #froms == 0 then
		return frame.args.default	
	end
	
	if #froms == 2 then
		return froms[1] .. "・" .. froms[2] .. '形'
	end
	
	local result = ""
	for i, item in ipairs(froms) do
		if i == 1 then
			-- nothing
		elseif i == #froms then
			result = result .. '及び'
		else
			result = result .. '、'
		end
		
		result = result .. item
	end
	return result .. '形'
end

return export