モジュール:サンドボックス/翼のない堕天使/sandbox

モジュールの解説[作成]
local p = {}

function p.test()
	local newFrameArg = {}
	newFrameArg[1] = "Dollo's law"
	newFrameArg[2] = "en"
	newFrameArg[3] = "Dollo's law"
	newFrameArg[4] = "fr"
	newFrameArg[5] = "Dollo's law"
	newFrameArg['view'] = 1
	newFrameArg['title'] = "リンク先の項目はまだありません。新規の執筆や他言語版からの翻訳が望まれます。"
	newFrameArg['label'] = "Dollo"
	local newFrame = { args = newFrameArg }
	return p.otherLangLinkList(newFrame)
end

function p.otherLangLinkList(frame)

	local args = frame:getParent().args

    local label = ""
	if args['label'] ~= "" and args['label'] ~= nil then
		label = "|" .. args['label']
	end
	
	if args['view'] ~= "" and args['view'] ~= nil then
		local result = {}
		
		-- ツールチップ指定
		result[1] = string.format(
			'<span title=%s>[[%s%s]]',
			args['title'],
			args[1],
			label
			)
			
		if args[2] ~= "" and args[3] ~= "" then
			-- フォント指定
			result[2] = '<span style="font-size: 0.77em; font-weight: normal;" class="noprint">'

			-- 改行指定対応
			if args['br'] == "" or args['br'] == nil then
				result[3] = ""
			else
				result[3] = '<br/>'
			end
			
			result[4] = '('
			local tmp = {}
			tmp[1] = p.otherLangLink(args[2], args[3])
			tmp[2] = p.otherLangLink(args[4], args[5])
			tmp[3] = p.otherLangLink(args[6], args[7])
			tmp[4] = p.otherLangLink(args[8], args[9])
			result[5] = table.concat(p._tableShorten(tmp), '、')
			result[6] = ')'
			
			result[7] = '</span>'
		end
		
		result[8] = '</span>'
		
		return table.concat(result)
	else
		return string.format(
			'[[%s%s]]',
			args[1],
			label
			)
	end
end

function p.otherLangLink(langCode, pageName)
	-- 引数が指定されていない場合は空文字を返す
	if langCode == "" or langCode == nil or pageName == "" or pageName == nil then
		return ""
	end
	
	local langDisp
	
	-- wikidataの場合は「wikidata」、それ以外の場合は言語名+「版」とする
	if langCode == 'wikidata' then
		langDisp = 'wikidata'
	else
		local mWikipediaLangName = require('モジュール:Wikipedia言語名')
	
		local newFrameArg = {}
		newFrameArg[1] = langCode
		local newFrame = { args = newFrameArg }
		
		langDisp = mWikipediaLangName.GetWikipediaPageName(newFrame) .. '版'
	end
	
	return string.format(
		'[[:%s:%s|%s]]',
		langCode,
		pageName,
		langDisp
		)
end

function p._tableShorten(t)
	local newTable = {}
	local i = 0
	for j,m in ipairs(t) do
		if m ~= "" and m ~= nil then
			i = i + 1
			newTable[i] = m
		end
	end
	
	return newTable
end

return p