模組:Nihongo

本页使用了标题或全文手工转换
被永久保护的模块
维基百科,自由的百科全书
文档图示 模块文档[查看] [编辑] [历史] [清除缓存]


參考模板:

require('Module:No globals')

local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')

local function ja(text)
	return '<span lang="ja" xml:lang="ja">-{' .. text ..'}-</span>'
end

local function romaji(text)
	return '<span lang="ja-Latn" xml:lang="ja-Latn" title="平文式罗马字">-{' .. text .. '}-</span>'
end

local function label(args, label, content)
	if yesno(args.lead) then
		return label .. ':' .. content
	end
	return content
end

local p = {}

function p.main(frame)
	local args = getArgs(frame, {frameOnly = true})
	return p._main(args)
end

function p._main(args)
	local bracketArr, temp = {}

	if args[1] then
		if args[2] then table.insert(bracketArr, label(args, '[[日语]]', ja(args[2]))) end
		if args['romaji'] then table.insert(bracketArr, label(args, '[[平文式罗马字|罗马字]]', romaji(args['romaji']))) end
		if args[3] then table.insert(bracketArr, args[3]) end
		if args[4] then table.insert(bracketArr, args[4]) end
		if #bracketArr > 0 then temp = '(' .. table.concat(bracketArr, ',') .. ')' end
		if args[5] then temp = temp and (temp .. ' ' .. args[5]) or (' ' .. args[5]) end
		if temp then return string.format('%s<span style="font-weight: normal;">%s</span>', args[1], temp) end
		return args[1]
	end
	
	if args['romaji'] then 
		if args[2] then table.insert(bracketArr, label(args, '[[日语]]', ja(args[2]))) end
		if args[3] then table.insert(bracketArr, args[3]) end
		if args[4] then table.insert(bracketArr, args[4]) end
		if #bracketArr > 0 then temp = '(' .. table.concat(bracketArr, ',') .. ')' end
		if args[5] then temp = temp and (temp .. ' ' .. args[5]) or (' ' .. args[5]) end
		if temp then return string.format('%s<span style="font-weight: normal;">%s</span>', romaji(args.romaji), temp) end
		return romaji(args.romaji)
	end
	
	if args[3] then 
		if args[2] then table.insert(bracketArr, label(args, '[[日语]]', ja(args[2]))) end
		if args[4] then table.insert(bracketArr, args[4]) end
		if #bracketArr > 0 then temp = '(' .. table.concat(bracketArr, ',') .. ')' end
		if args[5] then temp = temp and (temp .. ' ' .. args[5]) or (' ' .. args[5]) end
		if temp then return string.format('%s<span style="font-weight: normal;">%s</span>', args[3], temp) end
		return args[3]
	end
	
	if args[2] then
		if args[4] then temp = '(' .. args[4] .. ')' end
		if args[5] then temp = temp and (temp .. ' ' .. args[5]) or (' ' .. args[5]) end
		if temp then return string.format('%s<span style="font-weight: normal;">%s</span>', ja(args[2]), temp) end
		return ja(args[2])
	end
	
	if args[4] then
		if args[5] then return args[4] .. '<span style="font-weight: normal;"> ' .. args[5] .. '</span>' end
		return args[4]
	end
	
	if args[5] then
		return args[5]
	end
	
	return ''
	
end

return p