모듈:category tree/topic/utilities
보이기
이 모듈에 대한 설명문서는 모듈:category tree/topic/utilities/설명문서에서 만들 수 있습니다
local export = {}
local rsplit = mw.text.split
-- 레이블에 링크를 추가합니다. 한국어 환경에 맞춰 다음과 같이 작동합니다:
-- 1. `wikify`가 지정되면, 레이블을 한국어 위키백과에 연결합니다. (`[[w:ko:레이블|레이블]]`)
-- 2. `wikify`가 없으면, 위키낱말사전 내에서 해당 레이블 이름의 문서가 존재하는지 확인하고 링크를 시도합니다. (`[[레이블]]`)
-- 3. 링크할 수 있는 문서가 없으면, 레이블 텍스트를 그대로 반환합니다.
-- 참고: 영어판의 단수화(singularize) 로직은 한국어에 불필요하므로 제거.
function export.link_label(label, no_singularize, wikify)
local function term_exists(term)
local title = mw.title.new(term)
return title and title.exists
end
if wikify then
return "[[w:ko:" .. label .. "|" .. label .. "]]"
end
-- 레이블 전체가 하나의 문서로 존재하는지 확인
if term_exists(label) then
return "[[" .. label .. "]]"
else
-- 링크할 수 없으면 원본 텍스트 반환
return label
end
end
return export