Modul:Språklista

Från Wikipedia

Dokumentation [visa] [redigera] [historik] [rensa sidcachen]


Denna modul används av {{Språklista}} för att göra listor av Interwikilänkar.

-- Plans: To fetch "sitelinks" (article and language) from wikidata.
--        Currently it is not possible to fetch an entity which is not the one which is connected to 
--        the current page (until "tracking" is implemented).


local p = {}
 
function p.Iwlinklist(frame)
	
    local args = {}
    local parent_args = frame:getParent().args;
 
    for k, v in pairs(parent_args) do
        if v ~= '' then
            args[k] = v
        end
    end
    
    if args[1] == null or args[1] == '' then
    	-- error( "Minst en parameter krävs",0 )
    	return "<span class=\"error\">Fel: Minst en parameter krävs</span>"
    end

    -- special cases for first parameter  
    if string.sub(args[1], 1, 1) ~= "\"" or string.sub(args[1], -1) ~= "\"" then
    	-- error( "Första parametern måste vara omsluten av [[citattecken]]",0 )
    	return "<span class=\"error\">Fel: Första parametern måste vara omsluten av [[citattecken]]</span>"
    end
    -- Remove the quotation marks
    local name=string.sub(args[1], 2, -2);
    if #args == 1 then
    	return "'''[[" .. name .."]]'''";
    end
    
    -- Begin building the output text
    local text = "'''[[" .. name .."]] <small>+";
    for argnr = 1, #args do
    	-- Is it a new name (instead of a language)?
    	if string.sub(args[argnr], 1, 1) == "\"" or string.sub(args[argnr], -1) == "\"" then
    		name=string.sub(args[argnr], 2, -2);
    	else
    		-- Add language (for the last set name)  to the output text
    		text = text .. "[[:" .. args[argnr] .. ":" .. name .. "|" .. args[argnr] .. "]], ";
    	end
    end
    -- Remove the last comma in the list before output
    	text = string.sub(text, 1, -3) .. "</small>'''";
    return text 
end  
return p