Jump to content

Module:Translations/sandbox

From Wikisource
require('strict')

local p = {}

local getArgs = require('Module:Arguments').getArgs
local header = require('Module:Header/sandbox')._header
local lang = require('Module:Lang')._lang
local TableTools = require('Module:TableTools')

local function _translations(args)
	local current_frame = mw.getCurrentFrame()
	local current_title = mw.title.getCurrentTitle()
	
	args.translated = args.translated or current_title.text
	
	local headerArgs = TableTools.shallowClone(args)
	
	headerArgs.pretitle = 'English-language translations of'
	headerArgs.section = '' -- header distinguishes nil and blank args in some cases
	headerArgs.noyearcat = true
	headerArgs.noyear = args.year == nil
	headerArgs.disambiguation = nil
	headerArgs['allow-explicit-formatting'] = args.translated ~= nil
	headerArgs.header_class = 'ws-dynlayout-disable'
	headerArgs['language-required'] = true
	
	headerArgs.original = nil
	headerArgs.translated = nil
	
	local original = (args.original and args.language and lang({language = args.language, text = args.original})) or args.original
	local translated = tostring(mw.html.create('i'):wikitext(args.translated))
	
	if args.original and args.original ~= args.translated then
		headerArgs.title = original .. ' (' .. translated .. ')'
	else
		headerArgs.title = original or translated
	end
	
	local subNote = mw.html.create('div')
		:addClass('wst-sub-note')
		:tag('span')
			:attr('id', 'nofooter')
			:wikitext('English-language translations of ' .. tostring(mw.html.create('b'):wikitext(original or args.translated)) .. ' include:')
	
	return table.concat({
		current_frame:extensionTag('templatestyles', '', {src = 'Template:Translations/styles.css'}),
		header(headerArgs),
		current_frame:preprocess('__DISAMBIG__'),
		tostring(subNote),
		(current_title:inNamespaces(0, 114) and (args.category or '[[Category:' .. 'Translations pages' .. ']]')) or ''
	})
end

function p.translations(frame)
	return _translations(getArgs(frame))
end

return p