Pāriet uz saturu

Modulis:translations

No ''Wiktionary''

Šī moduļa dokumentāciju var izveidot Modulis:translations/doc lapā

local m_links = require("Module:links")

local export = {}

local interwiki_langs = {
	["nds-de"] = "nds",
	["nds-nl"] = "nds",
	["pdt"] = "nds",
}

local params = {
	[1] = {required = true},
	["sc"] = {},
	[2] = {},
	["alt"] = {},
	["tr"] = {},
	[3] = {},
	[4] = {},
	[5] = {},
	[6] = {},
}

-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
    local interwiki = frame.args["interwiki"]
    
    local args = require("Module:parameters").process(frame:getParent().args, params)
    local lang = args[1] or "und"
    local term = args[2] or (mw.title.getCurrentTitle().nsText == "Template" and "term") or nil
    local alt = args["alt"]
    local tr = args["tr"]
    
    local genders = {}
    table.insert(genders, args[3])
    table.insert(genders, args[4])
    table.insert(genders, args[5])
    table.insert(genders, args[6])
    
    lang = require("Module:languages").getByCode(lang) or error("Valodas kods \"" .. lang .. "\" nav derīgs.")
    sc = (sc and (require("Module:scripts").getByCode(sc) or error("Skripta kods \"" .. sc .. "\" nav derīgs.")) or nil)
	
    -- Don't show the interwiki link if there is nothing to link to.
    if term then
    	local wmlangs = {}
    	
    	if interwiki_langs[lang:getCode()] then
    		wmlangs = {require("Module:wikimedia languages").getByCode(interwiki_langs[lang:getCode()])}
    	else
    		wmlangs = 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 term:find("[[", nil, true) or #wmlangs == 0 then
        	interwiki = false
    	end
    	
    	if interwiki then
        	interwiki = "<span class=\"" .. interwiki .. "\">&nbsp;[[:"
        	.. wmlangs[1]:getCode() .. ":"
        	.. lang:makeEntryName(term)
        	.. "|(" .. wmlangs[1]:getCode() .. ")]]</span>"
    	end
	end
	
	if lang and lang:getCode()=='yue' and tr then
		tr = mw.ustring.gsub(tr,'([1-9])','<sup>%1</sup>')
		tr = mw.ustring.gsub(tr,'[-*]','⁻')
	end
	
    return m_links.full_link(term, alt, lang, sc, nil, nil, {interwiki = interwiki, tr = tr, genders = genders}, true)
end

return export