본문으로 이동

모듈:category tree/scripts

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

이 모듈에 대한 설명문서는 모듈:category tree/scripts/설명문서에서 만들 수 있습니다

local raw_categories = {}
local raw_handlers = {}

-- A list of Unicode blocks to which the characters of the script or scripts belong is created by this module
-- and displayed in script category pages.
local blocks_submodule = "Module:category tree/scripts/blocks"
local scripts_module = "Module:scripts"
local string_utilities_module = "Module:string utilities"

local m_str_utils = require(string_utilities_module)

local get_script_by_category_name = require(scripts_module).getByCategoryName
local pattern_escape = m_str_utils.pattern_escape

-----------------------------------------------------------------------------
--                                                                         --
--                              스크립트 레이블                            --
--                                                                         --
-----------------------------------------------------------------------------


--[=[
각 스크립트 레이블에 대해 다음 값들이 인식됩니다:
'description': 레이블에 대한 평이한 한국어 설명. 아래 설명된 특별 템플릿 치환이 인식됩니다.
'umbrella_parents': 이 레이블에 대한 '언어별 레이블' 포괄 분류의 상위 분류를 나열하는 테이블.
'umbrella_breadcrumb': '언어별 레이블' 포괄 분류에서 사용할 이동 경로. 기본값은 "스크립트별".
'catfix': 일반 원시 분류의 'catfix' 매개변수와 동일. 분류의 문서들이 올바른 글꼴로 표시되고 적절하게 링크되도록 할 언어 코드를 지정.

'description' 필드(및 아래에 초기화된 'root_...' 변수 값) 안에서 특별한 템플릿 형식의 매개변수를 사용할 수 있습니다.
이들은 해당하는 텍스트로 치환됩니다.
{{{code}}}: 스크립트 코드.
{{{codes}}}: 이 스크립트의 모든 별칭 코드 목록 (쉼표로 구분됨).
{{{codesplural}}}: {{{codes}}}가 둘 이상의 코드를 나열하면 "들", 아니면 빈 문자열.
{{{scname}}}: 분류가 속한 스크립트의 이름.
{{{sccat}}}: 스크립트의 주 분류 이름.
{{{scdisp}}}: 스크립트의 표시 형태.
{{{scprosename}}}: {{{scdisp}}}와 동일.
{{{Wikipedia}}}: 스크립트에 대한 위키백과 문서.
]=]

local script_labels = {}

script_labels["characters"] = {
	description = "{{{scprosename}}}의 모든 문자와, 발음 구별 기호가 붙은 버전 및 특정 언어에서 단일 문자로 인식되는 조합과 같은 가능한 변형들.",
	umbrella_parents = {"기본"},
	umbrella_breadcrumb = "문자 체계별 문자",
	catfix = "mul",
}

script_labels["appendices"] = {
	description = "{{{scprosename}}}에 대한 부록.",
	umbrella_parents = {"분류:부록"},
}

script_labels["languages"] = {
	description = "{{{scprosename}}}을(를) 사용하는 언어.",
	umbrella_parents = {"모든 언어"},
}

script_labels["templates"] = {
	description = "{{{scprosename}}}에 대한 미리 정의된 내용을 가진 틀.",
	umbrella_parents = {"틀"},
}

script_labels["modules"] = {
	description = "{{{scprosename}}}을 위한 기능을 구현하는 모듈.",
	umbrella_parents = {"모듈"},
}

script_labels["data modules"] = {
	description = "{{{scprosename}}}과 관련된 데이터를 포함하는 모듈.",
	umbrella_parents = {"데이터 모듈"},
}



-----------------------------------------------------------------------------
--                                                                         --
--                              원시(RAW) 분류                             --
--                                                                         --
-----------------------------------------------------------------------------


raw_categories["모든 문자 체계"] = {
	description = "이 분류는 위키낱말사전의 모든 문자 체계(script)에 대한 분류를 포함합니다.",
	additional = "전체 목록은 [[위키낱말사전:문자 체계 목록]]을 참고하십시오.",
	parents = {"기본"},
}

-- [[모듈:writing systems/data]]에 나열된 문자 체계 유형.
raw_categories["유형별 문자 체계"] = {
	description = "단어를 표현하는 방식에 따라 분류된 문자 체계.",
	parents = {{ name = "모든 문자 체계", sort = " " }},
	breadcrumb = "유형별",
}

raw_categories["아브자드"] = {
	description = "기본 기호가 자음을 나타내는 문자 체계. 일부 모음에 대한 글자가 있는 불순 아브자드도 있습니다.",
	parents = {"유형별 문자 체계"},
}

raw_categories["아부기다"] = {
	description = "기호가 자음과 모음의 조합을 나타내는 문자 체계. 다른 모음과 결합된 동일한 자음을 나타내는 기호는 대부분 형태가 유사합니다.",
	parents = {"유형별 문자 체계"},
}

raw_categories["알파벳"] = {
	description = "기호가 개별 음소를 나타내는 문자 체계.",
	parents = {"유형별 문자 체계"},
}

raw_categories["표어 문자"] = {
	description = "기호가 개별 단어를 나타내는 문자 체계.",
	parents = {"유형별 문자 체계"},
}

raw_categories["그림 문자"] = {
	description = "기호가 해당 단어가 가리키는 물리적 대상을 닮은 기호를 사용하여 개별 단어를 나타내는 문자 체계.",
	parents = {"유형별 문자 체계"},
}

raw_categories["반음절 문자"] = {
	description = "알파벳과 음절 문자의 조합인 문자 체계.",
	parents = {"유형별 문자 체계"},
}

raw_categories["음절 문자"] = {
	description = "기호가 자음과 모음의 조합을 나타내는 문자 체계. 다른 모음과 결합된 동일한 자음을 나타내는 기호는 대부분 형태가 다릅니다.",
	parents = {"유형별 문자 체계"},
}

for script_label, obj in pairs(script_labels) do
	local script_label_ko
	if script_label == "characters" then script_label_ko = "문자"
	elseif script_label == "appendices" then script_label_ko = "부록"
	elseif script_label == "languages" then script_label_ko = "언어"
	elseif script_label == "templates" then script_label_ko = "틀"
	elseif script_label == "modules" then script_label_ko = "모듈"
	elseif script_label == "data modules" then script_label_ko = "데이터 모듈"
	end
	
	raw_categories["문자 체계별 " .. script_label_ko] = {
		description = "다양한 특정 문자 체계의 " .. script_label_ko .. "이(가) 있는 분류.",
		breadcrumb = obj.umbrella_breadcrumb or "문자 체계별",
		parents = obj.umbrella_parents,
	}
end

-----------------------------------------------------------------------------
--                                                                         --
--                              원시(RAW) 핸들러                           --
--                                                                         --
-----------------------------------------------------------------------------



-- [[:분류:아랍 문자]]와 같은 "루트" 분류를 위한 도입 텍스트.
local root_topright = [=[<div style="clear: right; border: solid #aaa 1px; margin: 1 1 1 1; background: #f9f9f9; width: 250px; padding: 5px; text-align: left; float: right"><div style="text-align: center; margin-bottom: 10px; margin-top: 5px">'''{{{scdisp}}}'''</div>
{| style="font-size: 90%; background: #f9f9f9"
| style="vertical-align: middle; height: 35px;" | [[파일:Wikipedia-logo.png|35px|none|위키백과]] || ''{{{scprosename}}}에 대한 위키백과 문서''
|-
| colspan="2" style="padding-left: 50px; border-bottom: 1px solid lightgray;" | '''[[w:ko:{{{Wikipedia}}}|{{{Wikipedia}}}]]'''
|-
| style="vertical-align: middle; height: 35px;" | [[파일:Crystal kfind.png|35px|none|고려사항]] || {{{scdisp}}} 관련 사항
|-
| colspan="2" style="padding-left: 50px; border-bottom: 1px solid lightgray;" | '''[[위키낱말사전:{{{scdisp}}}에 대하여]]'''
|-
| style="vertical-align: middle; height: 35px;" | [[파일:Book notice.png|35px|none|정보]] || {{{scdisp}}} 정보
|-
| colspan="2" style="padding-left: 50px; border-bottom: 1px solid lightgray;" | '''[[부록:{{{sccat}}}]]'''
|-
| style="vertical-align: Middle; height: 35px;" | [[파일:Abc box.svg|35px|none|코드]] || {{{scdisp}}} 코드
|-
| colspan="2" style="padding-left: 50px; border-bottom: 1px solid lightgray;" | '''{{{code}}}'''
|}</div>]=]

-- "루트" 분류를 위한 간단한 설명.
local root_description = "이 분류는 '''{{{scprosename}}}'''의 주 분류입니다."

-- "루트" 분류를 위한 추가 설명 텍스트.
local root_additional = [=[[[부록:{{{sccat}}}]]에서 {{{scprosename}}}에 대한 정보를 찾아볼 수 있습니다.
위키낱말사전의 여러 곳에서 {{{scprosename}}}은(는) [[위키낱말사전:문자 체계 목록|코드{{{codesplural}}}]] {{{codes}}}(으)로 표현됩니다.]=]


-- 템플릿 표기 {{{}}}를 변수로 치환.
local function substitute_template_refs(text, sc)
	local displayForm = sc:getDisplayForm()
	local scname = sc:getCanonicalName()
	local codes = {}
	for code, data in pairs(mw.loadData("Module:scripts/data")) do
		if data[1] == scname then
			table.insert(codes, "'''" .. code .. "'''")
		end
	end
	
	if codes[2] then table.sort(codes) end
		
	local content = {
		code = sc:getCode(),
		codesplural = codes[2] and "들" or "",
		codes = table.concat(codes, ", "),
		scname = scname,
		sccat = sc:getCategoryName(),
		scdisp = displayForm,
		scprosename = displayForm,
		Wikipedia = sc:getWikipediaArticle(),
	}
		
	text = string.gsub(
		text,
		"{{{([^}]+)}}}",
		function (parameter)
			return content[parameter] or error("스크립트 분류 매개변수 '" .. parameter .. "'에 대한 값이 없습니다.")
		end)
	return text
end

local function get_root_additional(additional, sc)
	local ret = { additional }
	local systems = sc:getSystems()
	for _, system in ipairs(systems) do
		table.insert(ret, "\n\n{{{scname}}}은(는) ")
		table.insert(ret, system:getDisplayForm("singular"))
		table.insert(ret, "입니다.")
	end
	
	local blocks = require(blocks_submodule).print_blocks_by_canonical_name(sc:getCanonicalName())
	if blocks then
		table.insert(ret, "\n")
		table.insert(ret, blocks)
	end
	return substitute_template_refs(table.concat(ret), sc)
end


-- '아랍 문자' 및 '모스 부호', '수기 신호'와 같은 스크립트 분류를 처리하는 핸들러.
table.insert(raw_handlers, function(data)
	local sc = get_script_by_category_name(data.category)
	if not sc then return nil end
	
	local parents = {}
	local systems = sc:getSystems()
	for _, system in ipairs(systems) do
		table.insert(parents, system:getCategoryName())
	end
	table.insert(parents, "모든 문자 체계")
	
	local children = {}
	for script_label in pairs(script_labels) do
		local script_label_ko
		if script_label == "characters" then script_label_ko = "문자"
		elseif script_label == "appendices" then script_label_ko = "부록"
		elseif script_label == "languages" then script_label_ko = "언어"
		elseif script_label == "templates" then script_label_ko = "틀"
		elseif script_label == "modules" then script_label_ko = "모듈"
		elseif script_label == "data modules" then script_label_ko = "데이터 모듈"
		end
		table.insert(children, data.category .. " " .. script_label_ko)
	end

	return {
		canonical_name = sc:getCategoryName(),
		topright = substitute_template_refs(root_topright, sc),
		description = substitute_template_refs(root_description, sc),
		additional = get_root_additional(root_additional, sc),
		parents = parents,
		breadcrumb = sc:getCanonicalName(),
		extra_children = children,
		can_be_empty = true,
	}
end)

-- '아랍 문자 틀'과 같은 '스크립트 레이블' 분류를 처리하는 핸들러.
table.insert(raw_handlers, function(data)
	local sc, scname, label
	for lab_en, lab_obj in pairs(script_labels) do
		local lab_ko
		if lab_en == "characters" then lab_ko = "문자"
		elseif lab_en == "appendices" then lab_ko = "부록"
		elseif lab_en == "languages" then lab_ko = "언어"
		elseif lab_en == "templates" then lab_ko = "틀"
		elseif lab_en == "modules" then lab_ko = "모듈"
		elseif lab_en == "data modules" then lab_ko = "데이터 모듈"
		end
		
		scname, label = data.category:match("^(.-) (" .. pattern_escape(lab_ko) .. ")$")
		if scname then
			sc = get_script_by_category_name(scname)
			if sc then
				label = lab_en
				break
			end
		end
	end
	if not sc then return nil end
	
	local label_obj = script_labels[label]
	
	local parents = {
		{name = scname, sort = label},
		"문자 체계별 " .. (
			label == "characters" and "문자" or
			label == "appendices" and "부록" or
			label == "languages" and "언어" or
			label == "templates" and "틀" or
			label == "modules" and "모듈" or
			"데이터 모듈"
		),
	}
	return {
		canonical_name = sc:getCategoryName() .. " " .. label,
		description = substitute_template_refs(label_obj.description, sc),
		parents = parents,
		breadcrumb = label,
		catfix = label_obj.catfix,
		catfix_sc = label_obj.catfix and sc:getCode(),
	}
end)

return {RAW_CATEGORIES = raw_categories, RAW_HANDLERS = raw_handlers}