Salta al contegnùo

Modulo:Lost in translation

Da Wikisionario

La documentazione per questo modulo può essere creata in Modulo:Lost in translation/man

--DA CA.WIKT--

-- I meant "labels in translations".
-- Gets all Wikidata labels for a given Qid and returns them formated as the translation table.

local p = {}

-- dependencies
local Mlang = require('Module:łéngua') -- for language name, script and wikt prefix
local Mgeneral = require('Module:vec-zenerałe') -- for sorting key in local language
-- global variables
local lang_obj = mw.language.getContentLanguage()

-- on debug console: =p.getAllLabels({['args']={'Q3947'}})
function p.getAllLabels(frame)
	local id = frame.args[1]
	if not mw.wikibase.isValidEntityId(id) then return end
	local entity = mw.wikibase.getEntity(id)
	if not entity then return end
	local entity_labels = entity.labels
	local labels = {}
	for k, v in pairs(entity_labels) do
		if k ~= lang_obj:getCode() then -- local wiki language may have label in fallback languages
			local langcode = v.language
			labels[#labels + 1] = {code=langcode, name=Mlang.nom(langcode), script=Mlang.script(langcode), label=v.value}
		end
	end
	
	-- sort by language name
	local comparator = function(a, b)
		return Mgeneral.ordena(a.name) < Mgeneral.ordena(b.name)
	end
	table.sort(labels, comparator)
	
	-- format output
	local trans = {}
	trans[1], trans[2] = {}, {}
	for i, l in ipairs(labels) do
		local trans_lang = lang_obj:ucfirst(l.name) .. ': <span lang="' .. l.code .. '"' -- as Template:t
		if l.script ~= 'Latn' then
			trans_lang = trans_lang .. ' class="' .. l.script .. '"'
		end
		trans_lang = trans_lang .. '>' .. l.label .. '</span>'
		local wikt_lang = Mlang.wmproject(l.code)
		if wikt_lang then
			trans_lang = trans_lang .. ' <sup><small>[[:' .. wikt_lang .. ':' .. l.label .. '|(' .. l.code .. ')]]</small></sup>'
		else
			trans_lang = trans_lang .. ' <sup><small>(' .. l.code .. ')</small></sup>'
		end
		local trans_col = (i > math.floor((#labels + 1) / 2)) and 2 or 1
		table.insert(trans[trans_col], trans_lang)
	end
	
	local trans_cell = "<td style='background-color:#FFFFE0; vertical-align:top; width:48%; text-align:left;'>"
	local tbl = mw.html.create('table')
		:attr('role', 'presentation') -- as Template:trans-top
		:css('width', '100%')
			:tag('tr')
				:wikitext(trans_cell)
					:newline()
					:tag('ul')
						:wikitext('<li>' .. table.concat(trans[1], '</li><li>'))
						:wikitext('</li>')
					:done()
				:wikitext('</td>')
				:newline()
				:tag('td') -- as Template:trans-mid
					:css('width', '1%')
				:done()
				:newline()
				:wikitext(trans_cell)
					:newline()
					:tag('ul')
						:wikitext('<li>' .. table.concat(trans[2], '</li><li>'))
						:wikitext('</li>')
					:done()
				:wikitext('</td>')
			:done()
		:done()
	local ret = mw.html.create()
		:tag('div')
			:css('text-align', 'left')
			:css('margin-left', '10%')
			:css('font-style', 'italic')
			:wikitext('Traduccions importades de Wikidata <span style="font-size: smaller;">([[d:' .. id .. ']])</span>')
		:done()
		:newline()
		:node(tbl)
		:allDone()
	return ret
end

return p
Traesto fora da Wikipèdia - L'ençiclopedia łìbara e cołaboradiva in łéngua Vèneta "https://vec.wiktionary.org/w/index.php?title=Modulo:Lost_in_translation&oldid=33836"