모듈:연습장/Doyoon1995/zh
< 모듈:연습장
require("Module:No globals")
local p = {}
local getArgs = require("Module:Arguments").getArgs -- 변수 처리를 단순화하는 함수
local function intersects(lst, mst)
for key in pairs(mst) do
if lst[key] then
return true
end
end
return false
end
function p.zh(frame)
local args = getArgs(frame)
local title = mw.title.getCurrentTitle()
local zhdatalang = require("Module:Zh/data/" .. args["lang"])
local labels = zhdatalang.labels -- 각 언어 또는 발음에 표시할 라벨들
local articles = zhdatalang.articles -- 각 언어 또는 발음에 링크 걸 문서들
local labelsuffixes = zhdatalang.labelsuffixes
local suffixesarticles = zhdatalang.suffixesarticles
local isocodes = zhdatalang.isocodes -- 각 언어 또는 발음의 ISO 코드들
local cats = zhdatalang.cats
local pinyins = zhdatalang.pinyins -- 한어 병음을 제외한 병음들
local hanguls = zhdatalang.hanguls -- 한글 표기들
local superscript = zhdatalang.superscript -- 숫자와 "*" 또는 "°"를 자동 위 첨자 할 발음들
local ignorefirst = zhdatalang.ignorefirst
local savefirst = zhdatalang.savefirst
local orderlists = zhdatalang.orderlists -- 각 부분이 표시되는 순서의 방식들
local prefix = zhdatalang.prefix
-- change parameters and labels based on other parameters
if labels["p"] then
if not args["p"] and args["hp"] then
-- hp an alias for p ([hanyu] pinyin)
args["p"] = args["hp"]
end
if intersects(args, pinyins) then
labels["p"] = "한어 병음"
end
end
if labels["t"] then
if args["s"] and args["s"] == args["t"] then
-- 일치하는 간번체자 병합
args["c"] = args["s"]
args["s"] = nil
args["t"] = nil
end
end
if not args[savefirst] and args[1] then
args[savefirst] = args[1]
end
if intersects(args, ignorefirst) then
-- if there is an irreplaceable first parameter treat it as the main paratmeter
args[savefirst] = nil
end
-- based on setting/preference specify order
local ordkey = "default"
if args["order"] and orderlists[args["order"]] then
ordkey = args["order"]
end
local body = "" -- 출력 문자열
local params -- HTML span을 위한 변수
local label -- 텍스트 앞에 붙는 언어 라벨
local val -- 텍스트
local uselinks = not (args["links"] == "no") -- 라벨 링크 추가 여부
local uselabels = not (args["labels"] == "no") -- 라벨 표시 여부
local useprefix = not (args["prefix"] == "no") -- 맨 앞에 언어 이름 부착 여부
local usesmall = not (args["small"] == "no") -- 언어 라벨 작게 하기 여부
-- go through all possible fields in loop, adding them to the output
for i, part in ipairs(orderlists[ordkey]) do
if args[part] then
-- build label
label = ""
if uselabels or hanguls[part] then
label = labels[part]
if (uselinks and articles[part]) or hanguls[part] then
label = "[[" .. articles[part] .. "|" .. label .. "]]"
end
if labelsuffixes[part] then
if uselinks and suffixesarticles[part] then
label = label .. "([[" .. suffixesarticles[part] .. "|" .. labelsuffixes[part] .. "]])"
else
label = label .. "(" .. labelsuffixes[part] .. ")"
end
end
if body == "" and useprefix and prefix[part] then
if uselinks then
label = "[[" .. labels[savefirst] .. "]] " .. label
else
label = labels[savefirst] .. " " .. label
end
end
if hanguls[part] then
label = "<sup>[" .. label .. "]</sup>"
else
label = label .. ": "
end
if usesmall then
label = label .. "</small>"
if not hanguls[part] then
label = "<small>" .. label
end
end
end
-- build value
val = args[part]
if cats[part] and title.namespace == 0 then
-- if has associated category AND current page in article namespace, add category
val = cats[part] .. val
end
if isocodes[part] then
-- add span for language if needed
params = {["lang"] = isocodes[part], ["xml:lang"] = isocodes[part]}
val = mw.text.tag({name = "span", attrs = params, content = val})
elseif part:sub(1, 3) == "ipa" then
params = {["class"] = "IPA"}
val = mw.text.tag({name = "span", attrs = params, content = val})
end
if string.match(val, "</?sup>") then
val = val .. "[[분류:틀 zh에서 태그 sup를 사용하는 문서]]"
end
if superscript[part] then
-- superscript
val = val:gsub("([%d%*°]+)", "<sup>%1</sup>"):gsub("<sup><sup>([%d%*°]+)</sup></sup>", "%1")
end
if usesmall and hanguls[part] then
val = "<small>" .. val
end
-- add both to body
if body > "" then
if hanguls[part] then
body = body .. " "
else
body = body .. ", "
end
end
if hanguls[part] then
body = body .. val .. label
else
body = body .. label .. val
end
end
end
return body
end
return p