Module:translations/sandbox

Wiktionary වෙතින්

Sandbox for Module:translations. Test changes here.

Tests for merging {{t-needed}} into {{t}}:

  • Lua දෝෂය in Module:template_demo at line 5: attempt to call field 'shallowClone' (a nil value).
  • Lua දෝෂය in Module:template_demo at line 5: attempt to call field 'shallowClone' (a nil value).
  • Lua දෝෂය in Module:template_demo at line 5: attempt to call field 'shallowClone' (a nil value).
  • Lua දෝෂය in Module:template_demo at line 5: attempt to call field 'shallowClone' (a nil value).
  • Lua දෝෂය in Module:template_demo at line 5: attempt to call field 'shallowClone' (a nil value).

local m_languages = require("Module:languages")
local m_links = require("Module:links")
local m_params = require("Module:parameters")
local m_data = mw.loadData("Module:translations/data")
local m_params_data = mw.loadData("Module:parameters/data").translations

local export = {}

-- Implements {{t}} and {{t+}}.
function export.show(frame)
	local args = m_params.process(frame:getParent().args, m_params_data.show)
	
	local terminfo = {
		lang = m_languages.getByCode(args[1]) or m_languages.err(args[1], 1),
		sc = (args["sc"] and (require("Module:scripts").getByCode(args["sc"]) or error("The script code \"" .. args["sc"] .. "\" is not valid.")) or nil),
		term = args[2] or (mw.title.getCurrentTitle().nsText == "Template" and "term") or nil,
		alt = args["alt"],
		id = args["id"],
		genders = args[3],
		tr = args["tr"],
		ts = args["ts"],
		lit = args["lit"],
		interwiki = frame.args["interwiki"],
		}
	
	return export.show_terminfo(terminfo)
end

function export.show_terminfo(terminfo, no_check_redundant_translit)
	-- Translations must be for mainspace languages
	if not terminfo.lang:hasType("regular") then
		error("Translations must be for attested and approved main-namespace languages.")
	end
	
	-- Don't show the interwiki link if there is nothing to link to.
	if terminfo.term then
		-- Track translations for particular languages
		if m_data.tracked[terminfo.lang:getCode()] then
			require("Module:debug/track")("translations/" .. terminfo.lang:getCode())
		end
		
		local wmlangs = {}
		
		if m_data.interwiki_langs[terminfo.lang:getCode()] then
			wmlangs = {require("Module:wikimedia languages").getByCode(m_data.interwiki_langs[terminfo.lang:getCode()])}
		else
			wmlangs = terminfo.lang:getWikimediaLanguages()
		end
		
		-- Don't show the interwiki link if the language is not recognised by Wikimedia
		-- or if the term contains links (for SOP translations)
		if terminfo.term:find("[[", nil, true) or #wmlangs == 0 then
			terminfo.interwiki = false
		end
		
		if wmlangs[1] and m_data.ignore_caps[wmlangs[1]:getCode()] then
			terminfo.term2 = terminfo.term:gsub("^%^", "")
		end
		
		if terminfo.interwiki then
			terminfo.interwiki =
				"<span class=\"" .. terminfo.interwiki .. "\">&nbsp;[[:" ..
				wmlangs[1]:getCode() .. ":" ..
				(terminfo.lang:makeEntryName(terminfo.term2 or terminfo.term)) ..
				"|(" .. wmlangs[1]:getCode() .. ")]]</span>"
		end
	else
		-- Track what entries currently don't provide a term
		require("Module:debug/track")("translations/no term")
		require("Module:debug/track")("translations/no term/" .. terminfo.lang:getCode())
	end
	
	if terminfo.lang and m_data.need_super[terminfo.lang:getCode()] and terminfo.tr then
		terminfo.tr = terminfo.tr:gsub("([1-9]%-?[1-9]?)", "<sup>%1</sup>")
	end
	
	return m_links.full_link(terminfo, "translation", true, no_check_redundant_translit)
end

-- Implements {{trans-top}}.
function export.top(frame)
	local args = m_params.process(frame:getParent().args, m_params_data.top)
	
	local title = args[1] and m_links.remove_links(args[1])
	
	local page_title = mw.title.getCurrentTitle()
	local categories = {}
	
	if (not title) and page_title.nsText == "" then
		table.insert(categories, "Translation table header lacks gloss")
	end
	
	local page_title, translation_subpage = page_title.text:gsub("/translations$", "")
	if translation_subpage == 1 then
		table.insert(categories, "Translation subpages")
	end
	
	if #categories > 0 then
		local lang = m_languages.getByCode("en")
		categories = require("Module:utilities").format_categories(categories, lang, nil, page_title)
	else
		categories = ""
	end
	
	local id = args["id"] or title
	
	local column_width = (args["column-width"] == "wide" or args["column-width"] == "narrow") and "-" .. args["column-width"] or ""
	
	local div = mw.html.create("div")
		:addClass("NavFrame")
		:node(mw.html.create("div")
			:addClass("NavHead")
			:css("text-align", "left")
			:css("cursor", "pointer")
			:wikitext((title or "Translations"))
		)
		:node(mw.html.create("div")
			:addClass("NavContent")
			:node(mw.html.create("table")
				:addClass("translations")
				:attr("role", "presentation")
				:css("width", "100%")
				:attr("data-gloss", title or "")
				:node(mw.html.create("tr")
					:node(mw.html.create("td")
						:addClass("translations-cell multicolumn-list" .. column_width)
						:css("background-color", "#ffffe0")
						:css("vertical-align", "top")
						:css("text-align", "left")
						:attr("colspan", "3")
					)
				)
			)
		)
	div = id and div:attr("id", "Translations-" .. id) or div
	div = tostring(div)
	
	return div:gsub("</td></tr></table></div></div>$", "") .. categories
end

-- Implements {{trans-bottom}}.
function export.bottom(frame)
	-- Check nothing is being passed as a parameter.
	m_params.process(frame:getParent().args, m_params_data.bottom)
	return "</table></div></div>"
end

-- Implements {{trans-see}}.
function export.see(frame)
	local args = m_params.process(frame:getParent().args, m_params_data.see)
	
	local inner = mw.html.create("div")
		:addClass("NavHead")
		:css("text-align", "left")
		:wikitext(args[1] .. " ")
		:node(mw.html.create("span")
			:css("font-weight", "normal")
			:wikitext("— ")
			:node(mw.html.create("i")
				:wikitext("see ")
			)
		)
	
	if #args[2] == 0 then
		table.insert(args[2], args[1])
	end
	
	local data = {}
	
	data.id = args["id"] and mw.uri.anchorEncode("Translations-" .. args["id"])
	
	local terms = {}
	for i, term in ipairs(args[2]) do
		data.term = args[2][i]
		table.insert(terms, m_links.plain_link(data, false))
	end
	
	inner = inner:wikitext(table.concat(terms, ",&lrm; "))
	
	return mw.html.create("div")
		:addClass("NavFrame")
		:node(mw.html.create("div")
			:addClass("pseudo NavFrame")
			:node(inner)
		)
end
	
return export
"https://si.wiktionary.org/w/index.php?title=Module:translations/sandbox&oldid=34908" වෙතින් සම්ප්‍රවේශනය කෙරිණි