Module:Translations

local m_links = require("Module:links")

local export = {}

local interwiki_langs = {
	["ckb"] = "ku",
	["kmr"] = "ku",
	["lki"] = "ku",
	["nds-de"] = "nds",
	["nds-nl"] = "nds",
	["pdt"] = "nds",
	["sdh"] = "ku",
}

local ignore_caps = {
	["ko"] = true,
}

local tracked = {
	["se"] = true,
}

-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
	local params = {
		[1] = {required = true, default = "und"},
		[2] = {},
		[3] = {list = true},
		["alt"] = {},
		["id"] = {},
		["sc"] = {},
		["tr"] = {},
		["ts"] = {},
		["lit"] = {},
		["xs"] = {},
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local terminfo = {
		lang = require("Module:languages").getByCode(args[1]) or args[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"],
		xs = args["xs"],
		interwiki = frame.args["interwiki"],
		}
	
	return export.show_terminfo(terminfo)
end

function export.show_terminfo(terminfo)	
	-- Translations must be for mainspace languages
	if terminfo.lang:getType() == "reconstructed" or terminfo.lang:getType() == "appendix-constructed" 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 tracked[terminfo.lang:getCode()] then
			require("Module:debug").track("translations/" .. terminfo.lang:getCode())
		end
		
		local wmlangs = {}
		
		if interwiki_langs[terminfo.lang:getCode()] then
			wmlangs = {require("Module:wikimedia languages").getByCode(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 ignore_caps[wmlangs[1]:getCode()] then
			terminfo.term2 = mw.ustring.gsub(terminfo.term, "^%^", "")
		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
	
	-- languages needing superscripts in tr
	need_super = {
		["yue"] = true, ["gan"] = true, ["hak"] = true,
		["cjy"] = true, ["nan"] = true, ["hsn"] = true,
	}
	
	if terminfo.lang and need_super[terminfo.lang:getCode()] and terminfo.tr then
		terminfo.tr = mw.ustring.gsub(terminfo.tr, '([1-9]%-?[1-9]?)','<sup>%1</sup>')
	end
	
	return m_links.full_link(terminfo, "translation", true)
end

return export

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.