模組:Ko-etym

維基詞典,自由的多語言詞典


local export = {}

local m_lang = require("Module:languages")

-- This module implements {{ko-etym-*}} (currently only {{ko-etym-native}}).

local refs = {
	{{"1", "hh"}, "[[wikisource:ko:훈민정음#訓民正音解例|{{lang|ko|訓民正音解例 / 훈민정음해례}}]]》,1446年", "okm"},
	{{"2", "he"}, "[[wikisource:ko:훈민정음언해|{{lang|ko|訓民正音諺解本 / 훈민정음언해본}}]]》,1446年", "okm"},
	{{"3", "ss", "석보"}, "{{lang|ko|釋譜詳節 / 석보상절}}》,1447年", "okm"},
	{{"4", "yb", "용가"}, "[[wikisource:ko:용비어천가|{{lang|ko|龍飛御天歌 / 용비어천가}}]]》,1447年", "okm"},
	{{"5", "wc"}, "[[wikisource:ko:월인천강지곡|{{lang|ko|月印千江之曲 / 월인천강지곡}}]]》,1449年", "okm"},
	{{"6", "sy"}, "{{lang|ko|禪宗永嘉集諺解 / 선종영가집언해}}》,1456年", "okm"},
	{{"7", "ws", "wi", "월석"}, "{{lang|ko|月印釋譜 / 월인석보}}》,1459年", "okm"},
	{{"8", "ne"}, "{{lang|ko|楞嚴經諺解 / 능엄경언해}}》,1461年", "okm"},
	{{"9", "mb"}, "{{lang|ko|妙法蓮華經諺解 / 묘법연화경언해}}》,1463年", "okm"},
	{{"10", "wg"}, "{{lang|ko|圓覺經諺解 / 원각경언해}}》,1465年", "okm"},
	{{"11", "be"}, "{{lang|ko|法語諺解 / 법어언해}}》,1466年", "okm"},
	{{"12", "nh"}, "{{lang|ko|御製內訓 / 어제내훈}}》,1475年 ", "okm"},
	{{"13", "gg"}, "{{lang|ko|救急方諺解 / 구급방언해}}》,1466年", "okm"},
	{{"14", "bdb"}, "{{lang|ko|分類杜工部詩諺解 / 분류두공부시언해}}》,1481年", "okm"},
	{{"15", "nm"}, "{{lang|ko|南明集諺解 / 남명집언해}}》,1482年", "okm"},
	{{"16", "br"}, "{{lang|ko|百聯抄解 / 백련초해}}》,16世紀中葉", "okm"},
	{{"17", "bs"}, "{{lang|ko|飜譯小學 / 번역소학}}》,1517年", "okm"},
	{{"18", "bn"}, "{{lang|ko|飜譯老乞大 / 번역노걸대}}》,1517年", "okm"},
	{{"19", "ir"}, "{{lang|ko|二倫行實圖 / 이륜행실도}}》,1518年(玉山書院本)", "okm"},
	{{"20", "hm"}, "{{lang|ko|訓蒙字會 / 훈몽자회}}》,1527年", "okm"},
	{{"21", "gh"}, "{{lang|ko|救荒撮要 / 구황촬요}}》,1554年", "okm"},
	{{"22", "sj"}, "{{lang|ko|新增類合 / 신증유합}}》,1576年", "okm"},
	{{"23", "se"}, "{{lang|ko|小學諺解 / 소학언해}}》,1586年", "okm"},
	{{"24", "gci"}, "{{lang|ko|癸丑日記 / 계축일기}}》,1600年左右 ", "ko-ear"},
	{{"25", "etj"}, "{{lang|ko|諺解胎産集要 / 언해태산집요}}》,1608年", "ko-ear"},
	{{"26", "edj"}, "{{lang|ko|諺解痘瘡集要 / 언해두창집요}}》,1608年", "ko-ear"},
	{{"27", "sge", "sgs"}, "{{lang|ko|禪家龜鑑諺解 / 선가귀감언해}}》,1610年(松广寺本)", "ko-ear"},
	{{"28", "mg"}, "{{lang|ko|磨鏡軒集 / 마경헌집}}》,1635年", "ko-ear"},
	{{"29", "erh"}, "{{lang|ko|語錄解 / 어록해}}》,1652年", "ko-ear"},
	{{"30", "sgg"}, "{{lang|ko|新刊救荒撮要 / 신간구황촬요}}》,1660年", "ko-ear"},
	{{"31", "pts"}, "{{lang|ko|朴通事諺解 / 박통사언해}}》,1677年", "ko-ear"},
	{{"32", "yhy", "유해역"}, "{{lang|ko|譯語類解 / 역어유해}}》,1690年", "ko-ear"},
	{{"33", "js"}, "{{lang|ko|正俗諺解 / 정속언해}}, 1518年({{lang|ko|李源周敎授本 / 이원주 교수본}})", "okm"},
	{{"34", "ys"}, "{{lang|ko|新傳煮取焰硝方諺解 / 신전자취염초방언해}}》,1635年", "ko-ear"},
	{{"35", "sg"}, "{{lang|ko|三綱行實圖 / 삼강행실도}}》,1511年", "okm"},
	{{"36", "boi"}, "{{lang|ko|分門瘟疫易解方 / 분문온역이해방}}》,1542年", "okm"},
	{{"37", "yyb"}, "{{lang|ko|譯語類解補 / 역어유해보}}》,1775年", "ko-ear"},
	{{"38", "ggg"}, "{{lang|ko|金剛經三家解 / 금강경삼가해}}》,1482年", "okm"},
	{{"39", "du"}, "{{lang|ko|東醫寶鑑 / 동의보감}}》,1613年", "ko-ear"},
	{{"40", "bo"}, "{{lang|ko|辟瘟新方 / 벽온신방}}》,1653年", "ko-ear"},
	{{"41", "yhmb", "myb"}, "{{lang|ko|蒙語類解補編 / 몽어유해보편}}》,1790年", "ko-ear"},
	{{"42", "dssh"}, "{{lang|ko|東國新續三綱行實圖 / 동국신속삼강행실도}}》,1617年", "ko-ear"},
	{{"43", "ge"}, "{{lang|ko|警民編諺解 / 경민편언해}}》,1658年", "ko-ear"},
	{{"44", "ggb"}, "{{lang|ko|救急簡易方諺解 / 구급간이방언해}}》,1489年", "okm"},
	{{"45", "ag"}, "{{lang|ko|樂學軌範 / 악학궤범}}》,1493年", "okm"},
	{{"46", "bj"}, "{{lang|ko|方言集釋 / 방언집석}}》,1778年", "ko-ear"},
	{{"47", "msg"}, "{{lang|ko|明聖經諺解 / 명성경언해}}》,1883年", "ko-ear"},
	{{"48", "gy"}, "{{lang|ko|鷄林類事 / 계림유사}}》,1103年", "oko-lat"},
	{{"49", "ghw"}, "{{lang|ko|國韓會話 / 국한회화}}》,1895年", "ko-ear"},
	{{"50", "mc"}, "{{lang|ko|馬經抄集諺解 / 마경초집언해}}》,1623~1649年", "ko-ear"},
	{{"51", "nob"}, "{{lang|ko|老朴輯覽 / 노박집람}}》,1517年", "okm"},
	{{"52", "cm"}, "{{lang|ko|捷解蒙語 / 첩해몽어}}》,1790年", "ko-ear"},
	{{"53", "bb"}, "{{lang|ko|飜譯朴通事 / 번역박통사}}》,1517年以前", "okm"},
	{{"54", "sus"}, "{{lang|ko|三韻聲彙 / 삼운성휘}}》,1751年", "ko-ear"},
	{{"55", "dy"}, "{{lang|ko|同文類解 / 동문유해}}》,1748年", "ko-ear"},
	{{"56", "ng"}, "{{lang|ko|盧溪歌 / 노계가}}》,1636年", "ko-ear"},
	{{"57", "jg"}, "{{lang|ko|朝野記聞 / 조야기문}}》,1684年", "ko-ear"},
	{{"58", "ye"}, "{{lang|ko|女四書諺解 / 여사서언해}}》,1736年", "ko-ear"},
	{{"59", "jh"}, "{{lang|ko|朝野會通 / 조야회통}}》,18世紀", "ko-ear"},
	{{"60", "ij"}, "{{lang|ko|林花鄭延 / 임화정연}}》,18世紀", "ko-ear"},
	{{"61", "jgw"}, "{{lang|ko|朝鮮館驛語 / 조선관역어}}》,1403~1424年", "okm"},
	{{"62", "sc"}, "{{lang|ko|石峰千字文 / 석봉천자문}}》,1583年", "okm"},
	{{"63", "ns"}, "{{lang|ko|南槎錄 / 남사록}}》,1601年", "ko-ear"},
	{{"64", "tj"}, "{{lang|ko|眈羅志 / 탐라지}}》,1653年", "ko-ear"},
	{{"65", "me"}, "{{lang|ko|孟子諺解 / 맹자언해}}》,1590年", "okm"},
	{{"66", "gre"}, "{{lang|ko|家禮諺解 / 가례언해}}》,1632年", "ko-ear"},
	{{"67", "tsg"}, "{{lang|ko|太上感應篇圖說諺解 / 태상감응편도설언해}}》,1852年", "ko-ear"},
	{{"68", "chi"}, "{{lang|ko|七大萬法 / 칠대만법}}》,1569年", "okm"},
	{{"69", "gcj"}, "{{lang|ko|光州千字文 / 광주천자문}}》,1575年", "okm"},
	{{"70", "hyg"}, "{{lang|ko|鄕藥救急方 / 향약구급방}}》,1236年", "oko-lat"},
	{{"71", "ny"}, "{{lang|ko|諺解臘藥症治方 / 언해납약증치방}}》,17世紀", "ko-ear"},
	{{"72", "csg"}, "{{lang|ko|闡義昭鑑 / 천의소감}}》,1756年", "ko-ear"},
}

local ref_table = {}

for _, ref in ipairs(refs) do
	local keys, text, langcode = unpack(ref)
	for _, key in ipairs(keys) do
		ref_table[key] = {text, langcode}
	end
end

-- Implementation of {{ko-etym-native}}.
-- The shorthand parameter for first attestations will be deprecated soon in favor of creating actual entries or citation pages for Middle Korean.
-- See discussion at [[Wiktionary:Beer parlour/2019/September#First attestations in the etymology section]].
function export.ko_etym_native(frame)
	local params = {
		[1] = {},
		["also"] = {type = "boolean"},
		[2] = {alias_of = "form"},
		["form"] = {},
		[3] = {alias_of = "yale"},
		["yale"] = {},
		[4] = {alias_of = "year"},
		["year"] = {},
		["hangul"] = {type = "boolean"},
		["dot"] = {default = "."},
		["nodot"] = {type = "boolean"},
		["nocat"] = {type = "boolean"},
	}
		
	local parargs = frame:getParent().args
	if parargs["dot"] == "" then
		require("Module:debug").track("ko-etym/ko-etym-native/empty-dot")
	end
	local args = require("Module:parameters").process(parargs, params)

	local parts = {}
	local categories = {}

	if not args[1] then
		table.insert(parts, "朝鮮語自源詞")
	else
		local text, langcode
		if ref_table[args[1]] then
			text, langcode = unpack(ref_table[args[1]])
			text = text:gsub("{{lang|([a-z]+)|(.-)}}", function(langtextcode, langtext)
				local lang = m_lang.getByCode(langtextcode, true)
				return require("Module:script utilities").tag_text(langtext, lang)
			end)
		else
			if not args.year then
				error("1='" .. args[1] .. "' 非已知的參考著作,所以須提供 year= 參數")
			end
			text = args[1] .. "》," .. args.year
			if args.year:find("^[0-9]+$") then
				if tonumber(args.year) < 1300 then
					langcode = "oko-lat"
				elseif tonumber(args.year) < 1598 then
					langcode = "okm"
				else
					langcode = "ko-ear"
				end
			else
				langcode = "okm"
			end
		end
		local first
		if args.also then
			first = "也"
		else
			first = "最早"
		end
		if args.hangul then
			table.insert(parts, "以[[諺文]]書寫,")
			table.insert(parts, mw.getContentLanguage():lcfirst(first))
		else
			table.insert(parts, first)
		end
		table.insert(parts, "見於《")
		if langcode == "oko-lat" then
			-- table.insert(categories, "最早出現於上古朝鮮語的朝鮮語詞")
		elseif langcode == "okm" then
			-- table.insert(categories, "最早出現於中古朝鮮語的朝鮮語詞")
		end
		table.insert(parts, text)

		if args.form then
			table.insert(parts, ",作")
			table.insert(parts, require("Module:etymology").format_inherited(m_lang.getByCode("ko"),
				{lang = m_lang.getByCode(langcode, true, "allow etym"),
				term = args.form,
				tr = "-",
				}))
			if args.yale then
				table.insert(parts, "([[w:耶魯拼音|耶魯拼音]]:''")
				table.insert(parts, args.yale)
				table.insert(parts, "'')")
			end
		end
	end

	if not args.nodot then
		table.insert(parts, args.period)
	end

	if not args.nocat then
		table.insert(categories, "朝鮮語本土詞")
	end

	return table.concat(parts) .. require("Module:utilities").format_categories(categories, m_lang.getByCode("ko"))
end

return export