七日内新公告:全站维护公告
  • 你好~!欢迎来到萌娘百科镜像站!如需查看或编辑,请联系本站管理员注册账号。
  • 本镜像站和其他萌娘百科的镜像站无关,请注意分别。

Module: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</s>', 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