มอดูล:etymology/specialized

จาก วิกิพจนานุกรม พจนานุกรมเสรี
local export = {}


-- This function handles all the messiness of different types of specialized borrowings. It should insert any
-- borrowing-type-specific categories into `categories` unless `nocat` is given, and return the text to display
-- before the source + term (or "" for no text).
function export.get_specialized_borrowing_text_insert_cats(bortype, categories, lang, source, nocap, nocat, senseid)
	local function non_glossary_link(entry, text)
		text = text or entry
		if not nocap and not senseid then
			text = mw.getContentLanguage():ucfirst(text)
		end
		if senseid then
			senseids = mw.text.split(senseid, '!!')
			output = {}
			for i, id in ipairs(senseids) do
				if i == 1 and not nocap then
					uc = '|uc=1'
				else
					uc = ''
				end
				table.insert(output, mw.getCurrentFrame():preprocess('{{senseno|' .. lang:getCode() .. '|' .. id .. uc .. '}}'))
			end
			if senseid:find('!!') then
				copula = ' are '
				article = ''
				plural = 's'
			else
				copula = ' is '
				article = ' a '
				plural = ''
			end
			return mw.text.listToText(output) .. copula .. article .. '[[' .. entry .. '|' .. text .. plural .. ']]'
		else
			return "[[" .. entry .. "|" .. text .. "]]"
		end
	end


	local function glossary_link(entry, text)
		text = text or entry
		return non_glossary_link("ภาคผนวก:อภิธานศัพท์#" .. entry, text)
	end

	local function inscat(cat)
		--table.insert(categories, lang:getCanonicalName() .. " " .. cat)
		table.insert(categories, cat)
	end

	local text, category
	if bortype == "calque" then
		text = glossary_link("แปลตรงตัว") .. "จาก"
		category = "ศัพท์LANGที่แปลตรงตัวจากSOURCE"
	elseif bortype == "partial-calque" then
		text = glossary_link("แปลตรงตัวบางส่วน") .. "จาก"
		category = "ศัพท์LANGที่แปลตรงตัวบางส่วนจากSOURCE"
	elseif bortype == "semantic-loan" then
		text = glossary_link("ยืมความหมาย") .. "จาก"
		category = "ศัพท์LANGที่ยืมความหมายจากSOURCE"
	elseif bortype == "transliteration" then
		text = glossary_link("ถอดอักษร") .. "จาก"
		category = "ศัพท์LANGที่ถอดอักษรจากSOURCE"
		-- It seems the intent of the former code was to insert two categories, but it never worked.
		-- if not nocat then
		--	inscat(" terms borrowed from " .. source:getDisplayForm())
		-- end
	elseif bortype == "phono-semantic-matching" then
		text = glossary_link("เข้าคู่เสียง-ความหมาย") .. "จาก"
		category = "ศัพท์LANGที่เข้าคู่เสียง-ความหมายจากSOURCE"
	else
		local lang_is_source = lang:getCode() == source:getCode()
		if not nocat then
			if lang_is_source then
				inscat("ศัพท์" .. lang:getCategoryName() .. "ที่ยืมสองครั้ง")
			else
				inscat("ศัพท์" .. lang:getCategoryName() .. "ที่ยืมมาจาก" .. source:getCategoryName())
				--category = bortype .. " borrowings from "
			end
		end
	
		if bortype == "learned" then
			text = glossary_link("ยืมโดยเรียนรู้") .. "จาก"
			category = "ศัพท์LANGที่ยืมโดยเรียนรู้จากSOURCE"
		elseif bortype == "semi-learned" then
			text = glossary_link("ยืมโดยกึ่งเรียนรู้") .. "จาก"
			category = "ศัพท์LANGที่ยืมโดยกึ่งเรียนรู้จากSOURCE"
		elseif bortype == "orthographic" then
			text = glossary_link("ยืมอักขรวิธี") .. "จาก"
			category = "ศัพท์LANGที่ยืมอักขรวิธีจากSOURCE"
		elseif bortype == "unadapted" then
			text = glossary_link("ยืมโดยไม่ดัดแปลง") .. "จาก"
			category = "ศัพท์LANGที่ยืมโดยไม่ดัดแปลงจากSOURCE"
		else
			error("Internal error: Unrecognized bortype: " .. bortype)
		end
	end

	if category and not nocat then
		--[[
		local sourcedisp = source:getDisplayForm()
		if category:find("SOURCE") then
			category = category:gsub("SOURCE", sourcedisp)
		else
			category = category .. sourcedisp
		end
		--]]
		category = category:gsub("SOURCE", source:getCategoryName()):gsub("LANG", lang:getCategoryName())
		inscat(category)
	end

	return text
end


function export.specialized_borrowing(bortype, lang, terminfo, sort_key, nocap, notext, nocat, senseid)
	local m_etymology = require("Module:etymology")
	local categories = {}
	local source = terminfo.lang
	local text = export.get_specialized_borrowing_text_insert_cats(bortype, categories, lang, source, nocap, nocat, senseid)
	
	text = notext and "" or text
	return text .. m_etymology.format_etyl(lang, source, sort_key, categories, nocat) ..
		m_etymology.process_and_create_link(terminfo, template_name)
end


function export.specialized_multi_borrowing(bortype, lang, sc, sources, terminfo, sort_key, nocap, notext, nocat, conj, senseid)
	local categories = {}
	local text

	for _, source in ipairs(sources) do
		text = export.get_specialized_borrowing_text_insert_cats(bortype, categories, lang, source, nocap, nocat, senseid)
	end
	
	text = notext and "" or text
	return text .. require("Module:etymology/multi").format_sources(lang, sc, sources, terminfo, sort_key, categories, nocat, conj) ..
		require("Module:etymology").process_and_create_link(terminfo, template_name)
end


return export