본문으로 이동

모듈:usex/templates

위키낱말사전, 말과 글의 누리

모듈:usex/templates예문과 관련된 기능을 담당하는 모듈입니다.

  • usex: 예문 텍스트 (필수)[해설 1]
  • lang: 예문 언어의 ISO 언어코드 (필수)
  • termlang: 텍스트와 다른 용어의 언어 객체 (기본값은 lang).
  • sc: 텍스트의 스크립트 객체 (지정되지 않으면 자동 감지).
  • quote: 인용문일 경우 지정 (CSS 클래스가 다르게 적용).[해설 2]
  • inline: 인라인 형식으로 표시할 경우 지정.
  • translation: 외국어 예문 또는 인용문의 번역.
  • lit: 문자 그대로의 번역 (번역이 관용적일 경우).
  • normalization: 비표준 철자가 흔한 오래된 언어의 예문 또는 인용문의 표준화된 버전.
  • normsc: 표준화된 텍스트의 스크립트 객체.
  • transliteration: 예문의 음역 (지정되지 않으면 표준화된 텍스트를 음역).
  • transcription: 발음과 음역이 크게 다른 언어의 경우 예문의 전사.
  • subst: 음역 전에 예문/인용문과 표준화 텍스트에 수행할 대체 문자열.
  • q: 예문/인용문 텍스트 앞에 표시할 왼쪽 수식어 목록.
  • qq: 예문/인용문 텍스트 뒤에 표시할 오른쪽 수식어 목록.
  • translation: 한국어 외 단어에 대한 예문의 번역[해설 3]
  • ref: 출처 표시를 담당합니다.
  • orig: 원문 텍스트[해설 3]

해설

[편집]
  1. 만약 없을 경우 예외처리 구문을 생성합니다.
  2. 예문의 화자가 다른 화자의 말을 인용하는 상황을 가정하고 있을 경우, 이 옵션을 적용할 수 있습니다.
  3. 3.0 3.1 "차라투스트라는 이렇게 말했다"는 한국어로 쓰여졌지만 독일어를 사용하는 니체의 독일어 어록을 한국어로 번역한 것입니다. 말하다의 예문을 작성하기 위해 "차라투스트라는 이렇게 말했다"를 예문으로 사용할 수 있지만, 그것에 대한 독일어 원문을 표시하고 싶다면 orig이 사용됩니다.

하위 문서

[편집]

local export = {}

local usex_module = "Module:usex"
local yesno_module = "Module:yesno"
local m_languages = require("Module:languages")
local m_scripts = require("Module:scripts")

local usex_ja_module = "Module:usex/templates/ja"

local insert = table.insert
local rfind = mw.ustring.find

local function track(page)
	require("Module:debug").track("usex/templates/" .. page)
	return true
end

function export.usex_t(frame)
	local parent_args = frame:getParent().args
	local compat = require("Module:yesno")(parent_args.compat)
	
	local lang_param_name = compat and "lang" or 1
	local lang_code = parent_args[lang_param_name]
	
	if lang_code == "ja" then
		return require(usex_ja_module).show(frame)
	end
	
	local iargs = require("Module:parameters").process(frame.args, {
		["quote"] = {type = "boolean"},
		["inline"] = {type = "boolean"},
		["nocat"] = {type = "boolean"},
		["class"] = {},
		["compat"] = {type = "boolean"},
	})

	local compat = iargs.compat

	-- Template (parent) arguments
	local params = {
		[1] = {required = true}, -- lang
		[2] = {}, -- usex
		["termlang"] = {},
		["tr"] = {},
		["transliteration"] = {alias_of = "tr"},
		["ts"] = {},
		["transcription"] = {alias_of = "ts"},
		["sc"] = {},
		["norm"] = {},
		["normalization"] = {alias_of = "norm"},
		["normsc"] = {},
		["subst"] = {},
		["q"] = {list = true},
		["qualifier"] = {alias_of = "q", list = false},
		["qq"] = {list = true},
		["ref"] = {},
		["audio"] = {},
		[3] = {}, -- translation
		["t"] = {alias_of = 3},
		["translation"] = {alias_of = 3},
		["lit"] = {},
		["orig"] = {},
		["origlang"] = {},
		["origtr"] = {},
		["origts"] = {},
		["origsc"] = {},
		["orignorm"] = {},
		["orignormsc"] = {},
		["origsubst"] = {},
		["origq"] = {list = true},
		["origqq"] = {list = true},
		["origref"] = {},
		["source"] = {},
		["footer"] = {},
		["inline"] = {type = "boolean"},
		["brackets"] = {type = "boolean"},
		["nocat"] = {type = "boolean"},
		["sort"] = {},
		["m"] = {},
		["manyou"] = {alias_of = "m"},
		["manyou_kana"] = {},
		["m_kana"] = {alias_of = "manyou_kana"},
		["출처"] = {alias_of = "source", deprecated = true},
		["언어"] = {alias_of = 1, deprecated = true},
		["원문"] = {alias_of = 2, deprecated = true},
		["발음"] = {alias_of = "tr", deprecated = true},
	}

	if compat then
		params[1] = {required = true} -- usex
		params[2] = {} -- translation
		params[3] = nil
		params.lang = {required = true}
		params.t.alias_of = 2
		params.translation.alias_of = 2
	end

	local args = require("Module:parameters").process(parent_args, params)

	local lang = m_languages.getByCode(args[lang_param_name] or "und", lang_param_name, "allow etym")
	
	local sc = args.sc and m_scripts.getByCode(args.sc, "sc") or nil
	local normsc = args.normsc and m_scripts.getByCode(args.normsc, "normsc") or nil
	if normsc and not args.norm then
		error("normsc=를 사용하려면 norm=이 필요합니다.")
	end

	if #args.qq > 0 then track("qq") end
	if #args.q > 0 then track("q") end

	local termlang = args.termlang and m_languages.getByCode(args.termlang, "termlang", "allow etym")
	if termlang then
		insert(args.qq, 1, "in " .. lang:getCanonicalName())
	end

	local origlang, origsc, orignormsc
	if args.orig then
		origlang = args.origlang and m_languages.getByCode(args.origlang, "origlang", "allow etym")
		insert(args.origqq, 1, "in " .. origlang:getCanonicalName())
		origsc = args.origsc and m_scripts.getByCode(args.origsc, "origsc") or nil
		orignormsc = args.orignormsc and m_scripts.getByCode(args.orignormsc, "normsc") or nil
		if orignormsc and not args.orignorm then
			error("orignormsc=를 사용하려면 orignorm=이 필요합니다.")
		end
	else
		for _, noparam in ipairs { "origlang", "origtr", "origts", "origsc", "orignorm", "orignormsc", "origsubst", "origref" } do
			if args[noparam] then
				error(("%s=를 사용하려면 orig=이 필요합니다."):format(noparam))
			end
		end
		if #args.origq > 0 then error("origq=를 사용하려면 orig=이 필요합니다.") end
		if #args.origqq > 0 then error("origqq=를 사용하려면 orig=이 필요합니다.") end
	end

	local inline = args.inline or iargs.inline
	if inline ~= "auto" then
		inline = require(yesno_module)(inline)
	end
	
	local usex = args[compat and 1 or 2]

	local data = {
		lang = lang,
		termlang = termlang,
		sc = sc,
		normsc = normsc,
		usex = usex,
		translation = args[compat and 2 or 3],
		transliteration = args.tr,
		transcription = args.ts,
		normalization = args.norm,
		inline = inline,
		ref = ref,
		quote = iargs.quote,
		lit = args.lit,
		subst = args.subst,
		qq = #args.qq > 0 and args.qq or args.q,
		audio = args.audio,
		source = args.source,
		footer = args.footer,
		nocat = args.nocat or iargs.nocat,
		brackets = args.brackets,
		sortkey = args.sort,
		class = iargs.class,
		orig = args.orig,
		origlang = origlang,
		origtr = args.origtr,
		origts = args.origts,
		origsc = origsc,
		orignorm = args.orignorm,
		orignormsc = orignormsc,
		origsubst = args.origsubst,
		origq = args.origq,
		origqq = args.origqq,
		origref = args.origref,
	}

	local categories = {}
	if not (args.nocat or iargs.nocat) then
		for _, param in ipairs({"언어", "원문", "발음", "출처"}) do
			if parent_args[param] then
				insert(categories, "구식화된 예문 매개변수 " .. param .. " 사용/" .. lang:getCode())
			end
		end
	end
	data.categories = categories
	
	return require(usex_module).format_usex(data)
end

local ignore_prefixes = {
	"사용자:", "토론:", "위키낱말사전:사랑방", "위키낱말사전:질문방",
	"Wiktionary:Beer parlour", "Wiktionary:Translation requests",
	"Wiktionary:Grease pit", "Wiktionary:Etymology scriptorium",
	"Wiktionary:Information desk", "Wiktionary:Tea room",
	"Wiktionary:Requests for", "Wiktionary:Votes"
}

function export.page_should_be_ignored(page)
	for _, ip in ipairs(ignore_prefixes) do
		if rfind(page, "^" .. ip) then
			return true
		end
	end
	if rfind(page, " 토론:") then
		return true
	end
	return false
end

function export.page_should_be_ignored_t(frame)
	return export.page_should_be_ignored(frame.args[1]) and "true" or ""
end

return export