跳转到内容

Module:InfoboxImageVariant

本页使用了标题或全文手工转换
维基教科书,自由的教学读本

本模块爲資訊框處理模組Module:InfoboxImage的擴展版,支援需要字詞轉換的場合。

用法

[编辑]

可用參數同Module:InfoboxImage,但參數名後可附綴“-cn”“-tw”等地區代碼。若不附綴地區代碼則為各用字模式共用。

|image = {{#invoke:InfoboxImageVariant|main
  | size={{{image_size|}}}       | sizedefault=frameless
  | image={{{image|}}}           | alt={{{alt|}}}
  | image-hans={{{image-hans|}}} | alt-hans = {{{alt-hans|}}}
  | image-hant={{{image-hant|}}} | alt-hant = {{{alt-hant|}}}
  | image-cn={{{image-cn|}}}     | alt-cn={{{alt-cn|}}}
  | image-hk={{{image-hk|}}}     | alt-hk={{{alt-hk|}}}
  | image-mo={{{image-mo|}}}     | alt-mo={{{alt-mo|}}}
  | image-my={{{image-my|}}}     | alt-my={{{alt-my|}}}
  | image-sg={{{image-sg|}}}     | alt-sg={{{alt-sg|}}}
  | image-tw={{{image-tw|}}}     | alt-tw={{{alt-tw|}}}
}}

例子

[编辑]
{{#invoke:InfoboxImageVariant|main
  | size = 300px
  | image-hans = Milky Way Spiral Arm zh hans.svg | alt-hans = 银河系螺旋结构示意图
  | image-hant = Milky Way Spiral Arm zh hant.svg | alt-hant = 銀河系螺旋結構示意圖
}}
银河系螺旋结构示意图

require( 'strict' )
local infoboxImage = require('Module:InfoboxImage').InfoboxImage
local lc = require('Module:WikitextLC').selective

local getArgs = require('Module:Arguments').getArgs
local p = {}

function p.main(frame)
	local args = getArgs(frame)
	return p._main(args)
end

function p._main(args)
	local variety = {'', '-hans', '-hant', '-cn', '-hk', '-mo', '-my', '-sg', '-tw'}
	local varietyHans = {'-hans', '-cn', '-my', '-sg'}
	local varietyHant = {'-hant', '-hk', '-mo', '-tw'}
	local hansIndicator, hantIndicator = false, false
	
	for i, v in ipairs(varietyHans) do
		if args['image' .. v] then
			hansIndicator = true
			break
		end
	end

	for i, v in ipairs(varietyHant) do
		if args['image' .. v] then
			hantIndicator = true
			break
		end
	end

	if hansIndicator and hantIndicator then
		local content = {}

		for i, v in ipairs(variety) do
			if args['image' .. v] then
				content['zh' .. v] = infoboxImage{args = {
					image = args['image' .. v],
					size = args['size' .. v] or args.size,
					maxsize = args['maxsize' .. v] or args.maxsize,
					sizedefault = args['sizedefault' .. v] or args.sizedefault,
					link = args['link' .. v] or args.link,
					title = args['title' .. v] or args.title,
					border = args['border' .. v] or args.border,
					upright = args['upright' .. v] or args.upright,
					thumbtime = args['thumbtime' .. v] or args.thumbtime,
					center = args['center' .. v] or args.center,
					alt = args['alt' .. v] or args.alt,
				} }
			end
		end
	
		return lc(content)
	end
	
	for i, v in ipairs(variety) do
		if args['image' .. v] then
			return infoboxImage{args = {
				image = args['image' .. v],
				size = args['size' .. v] or args.size,
				maxsize = args['maxsize' .. v] or args.maxsize,
				sizedefault = args['sizedefault' .. v] or args.sizedefault,
				link = args['link' .. v] or args.link,
				title = args['title' .. v] or args.title,
				border = args['border' .. v] or args.border,
				upright = args['upright' .. v] or args.upright,
				thumbtime = args['thumbtime' .. v] or args.thumbtime,
				center = args['center' .. v] or args.center,
				alt = args['alt' .. v] or args.alt,
			} }
		end
	end

end

return p