Modul:Vorlage:Infobox PKW-Modell

Die Dokumentation für dieses Modul kann unter Modul:Vorlage:Infobox PKW-Modell/Doku erstellt werden

--[[  
Modul für Hilfsfunktionen für Vorlage:Infobox PKW-Modell
]]
local p = { }

function p.getCategoryForMarke(frame)
--[[  
	Kategorie zur Marke ermitteln (falls vorhanden)
	Parameter: 
	*	WikiMarkup zur Marke
	*	Modell
]]
	local marke = p._extractLinkTarget(frame.args[1])
	local modell = frame.args[2] or ""
	local wiki_markup_cat = ""
	-- Tabelle zur Übersetzung des Linkziels für die Marke (Lemma des entspr. Artikels) in die Kategorie
	local tab_cat = {
		 ["AC Cars"] = "AC Cars"
		,["Acura"] = "Acura"
		,["Adlerwerke"] = "Adlerwerke"
		,["Alfa Romeo"] = "Alfa Romeo"
		,["Allard"] = "Allard"
		,["Alpina Burkard Bovensiepen"] = "Alpina"
		,["Alpine (Automobilhersteller)"] = "Alpine-Rennwagen"
		,["American Motors Corporation"] = "American Motors Corporation"
		,["Armstrong Siddeley"] = "Armstrong-Siddeley-PKW"
		,["Aston Martin"] = "Aston Martin"
		,["Audi"] = "Audi-Automobil"
		,["Austin Motor Company"] = "Austin"
		,["Austin-Healey"] = "Austin"
		,["Autobianchi"] = "Autobianchi"
		,["AwtoWAS"] = "AwtoWAS"
		,["Bedford (Fahrzeughersteller)"] = "Bedford (Fahrzeughersteller)"
		,["Beijing Automobile Works"] = "Beijing Automobile Works"
		,["Bentley"] = "Bentley"
		,["Benz & Cie."] = "Benz & Cie."
		,["Berkeley Cars"] = "Berkeley Cars"
		,["Bitter Automobile"] = "Bitter (Automarke)"
		,["BMW-Pkw"] = "BMW-Automobil"
		,["BMW (Automarke)"] = "BMW-Automobil"
		,["BMW i"] = "BMW-Automobil"
		,["Bond Cars"] = "Bond Cars"
		,["Borgward"] = "Borgward-Automobil"
		,["Brabus"] = "Brabus"
		,["Bristol Cars"] = "Bristol Cars"
		,["Bugatti"] = "Bugatti"
		,["Bugatti Automobili"] = "Bugatti"
		,["Bugatti Automobiles"] = "Bugatti"
		,["Buick"] = "Buick"
		,["BYD Auto"] = "BYD"
		,["Cadillac"] = "Cadillac"
		,["Champion (deutsche Automarke)"] = "Champion (deutsche Automarke)"
		,["Chongqing Changan Automobile Company"] = "Changan"
		,["Chery Automobile"] = "Chery"
		,["Chevrolet"] = "Chevrolet"
		,["Chrysler"] = "Chrysler"
		,["Citroën"] = "Citroën-Automobil"
		,["Continental Division"] = "Continental Division"
		,["Corvette"] = "Chevrolet"
		,["Automobile Dacia"] = "Dacia"
		,["GM Daewoo"] = "GM Daewoo"
		,["DAF (Automobile)"] = "DAF"
		,["Daihatsu"] = "Daihatsu"
		,["Daimler-Motoren-Gesellschaft"] = "Daimler-Motoren-Gesellschaft"
		,["Daimler Motor Company"] = "Daimler Motor Company"
		,["Datsun"] = "Datsun"
		,["De Tomaso"] = "De Tomaso"
		,["DKW"] = "DKW-Automobil"
		,["Dodge"] = "Dodge"
		,["DS Automobiles"] = "DS Automobiles"
		,["Eagle (US-amerikanische Automarke)"] = "American Motors Corporation"
		,["Edsel"] = "Edsel"
		,["Emgrand"] = "Geely"
		,["Excalibur Automobile Corporation"] = "Excalibur Automobile Corporation"
		,["Facel"] = "Facel"
		,["Ferrari"] = "Ferrari-Automobil"
		,["Fiat (Marke)"] = "Fiat-Automobil"
		,["Ford"] = "Ford-Automobil"
		,["Freight Rover"] = "Freight Rover"
		,["Fuldamobil"] = "Fuldamobil"
		,["Gorkowski Awtomobilny Sawod"] = "Gorkowski Awtomobilny Sawod"
		,["General Motors"] = "General Motors"
		,["Hans Glas GmbH"] = "Hans Glas GmbH"
		,["GMC"] = "GMC"
		,["GAC Gonow Auto"] = "GAC Gonow Auto"
		,["Geely"] = "Geely"
		,["Goliath (Automobilhersteller)"] = "Goliath (Automobilhersteller)"
		,["Hillman (Unternehmen)"] = "Hillman"
		,["Hino Jidōsha"] = "Hino Jidōsha"
		,["Holden (Automarke)"] = "Holden"
		,["Holland Car"] = "Holland Car"
		,["Honda"] = "Honda-Automobil"
		,["Horch"] = "Horch"
		,["Hummer (Automarke)"] = "General Motors"
		,["Hyundai Motor Company"] = "Hyundai"
		,["Industrieverband Fahrzeugbau"] = "Industrieverband Fahrzeugbau"
		,["Barkas"] = "Industrieverband Fahrzeugbau"
		,["Imperial (Automarke)"] = "Chrysler"
		,["Infiniti"] = "Infiniti"
		,["Innocenti"] = "Innocenti"
		,["Ischmasch"] = "Ischmasch-Automobil"
		,["Iso Rivolta"] = "Iso Rivolta"
		,["Isuzu"] = "Isuzu"
		,["Iveco"] = "Iveco"
		,["Jaguar Cars"] = "Jaguar"
		,["Jeep"] = "Jeep"
		,["Jensen Motors"] = "Jensen"
		,["Kia Motors"] = "Kia"
		,["Lagonda"] = "Aston Martin"
		,["Lamborghini"] = "Lamborghini"
		,["Lancia"] = "Lancia"
		,["Land Rover"] = "Land Rover"
		,["LDV Limited"] = "LDV (Van)"
		,["Lexus"] = "Lexus"
		,["Leyland Motors"] = "Leyland Motors"
		,["Lincoln (Automarke)"] = "Lincoln"
		,["Lion-Peugeot"] = "Lion-Peugeot"
		,["Lloyd (Automarke)"] = "Lloyd (Automarke)"
		,["Lola Cars"] = "Lola Cars"
		,["Lotus Cars"] = "Lotus Cars"
		,["Maico"] = "Maico"
		,["Maruti Suzuki India"] = "Maruti"
		,["Maserati"] = "Maserati-Automobil"
		,["Maybach-Manufaktur"] = "Maybach"
		,["Mazda"] = "Mazda-Automobil"
		,["McLaren Automotive"] = "McLaren"
		,["Mercedes-Benz-PKW"] = "Mercedes-Benz-Automobil"
		,["Mercury (Automarke)"] = "Mercury"
		,["MG (Automarke)"] = "MG"
		,["Miele"] = "Miele"
		,["Mitsubishi Motors"] = "Mitsubishi Motors"
		,["Automobile Monteverdi"] = "Automobile Monteverdi"
		,["Société A. Marguerite"] = "Société A. Marguerite"
		,["Morris Motor Company"] = "Morris"
		,["Moskwitsch"] = "Moskwitsch"
		,["Nash Motors"] = "Nash"
		,["Nesselsdorfer Wagenbau-Fabriks-Gesellschaft"] = "Nesselsdorf"
		,["Nissan"] = "Nissan"
		,["NSU Motorenwerke"] = "NSU-Automobil"
		,["Oldsmobile"] = "Oldsmobile"
		,["Opel"] = "Opel-Automobil"
		,["Packard (Automobilhersteller)"] = "Packard"
		,["Panhard"] = "Panhard"
		,["Peugeot"] = "Peugeot-Automobil"
		,["Piaggio"] = "Piaggio"
		,["Plymouth (Automarke)"] = "Plymouth (Automobilhersteller)"
		,["Pontiac (Automarke)"] = "Pontiac"
		,["Porsche"] = "Porsche"
		,["Prince Jidōsha Kōgyō"] = "Prince Jidōsha Kōgyō"
		,["Protek Gesellschaft für Industrieentwicklungen"] = "Protek Gesellschaft für Industrieentwicklungen"
		,["Proton (Automobilhersteller)"] = "Proton"
		,["Reliant"] = "Reliant"
		,["Renault"] = "Renault-Automobil"
		,["Riley"] = "Riley"
		,["Rolls-Royce Motor Cars"] = "Rolls-Royce"
		,["Rover (Automobilhersteller)"] = "Rover"
		,["Saab Automobile"] = "Saab Automobile"
		,["Saab-Valmet"] = "Saab Automobile"
		,["Renault Samsung Motors"] = "Samsung"
		,["Saporisky Awtomobilebudiwny Sawod"] = "Saporisky Awtomobilebudiwny Sawod"
		,["Saturn Corporation"] = "General Motors"
		,["Sawod imeni Lichatschowa"] = "Sawod imeni Lichatschowa"
		,["Scion"] = "Scion"
		,["Seat"] = "Seat"
		,["Shijiazhuang Shuanghuan Automobile"] = "Shijiazhuang Shuanghuan Automobile"
		,["Simca"] = "Simca"
		,["Škoda Auto"] = "Škoda-Automobil"
		,["Smart (Automarke)"] = "Smart"
		,["Speranza (Automarke)"] = "Speranza (Automarke)"
		,["SsangYong Motor Company"] = "SsangYong"
		,["Standard Motor Company"] = "Standard Motor Company"
		,["Steyr-Daimler-Puch"] = "Steyr (Unternehmen)"
		,["Studebaker Corporation"] = "Studebaker"
		,["Subaru"] = "Subaru"
		,["Sunbeam"] = "Sunbeam"
		,["Suzuki"] = "Suzuki"
		,["Talbot (Automarke)"] = "Talbot (Automarke)"
		,["Tata Motors"] = "Tata"
		,["Tatra (Unternehmen)"] = "Tatra"
		,["Tesla, Inc."] = "Tesla, Inc."
		,["Toyopet"] = "Toyota"
		,["Toyota"] = "Toyota-Automobil"
		,["Trabant (Pkw)"] = "Industrieverband Fahrzeugbau"
		,["Triumph (Auto)"] = "Triumph-Automobil"
		,["TVR"] = "TVR"
		,["Uljanowski Awtomobilny Sawod"] = "Uljanowski Awtomobilny Sawod"
		,["Vanden Plas (England)"] = "Vanden Plas"
		,["Vauxhall Motors"] = "Vauxhall"
		,["Volkswagen"] = "Volkswagen-Automobil"
		,["Volvo Car Corporation"] = "Volvo"
		,["Wanderer-Werke"] = "Wanderer-Werke"
		,["Wartburg (Automarke)"] = "Industrieverband Fahrzeugbau"
		,["Willys-Overland"] = "Willys-Overland"
		,["Willys-Overland do Brazil"] = "Willys-Overland"
		,["Wolga (Automarke)"] = "Gorkowski Awtomobilny Sawod"
		,["Wolseley Motor Company"] = "Wolseley"
		,["Yenko Sportscars"] = "Yenko"
		,["Zastava"] = "Zastava"
		,["Saporisky Awtomobilebudiwny Sawod"] = "Saporisky Awtomobilebudiwny Sawod"
		,["Sawod imeni Lichatschowa"] = "Sawod imeni Lichatschowa"
		,["Zündapp"] = "Zündapp"
		}

	local cat = tab_cat[marke]
		
	if cat ~= nil then
		wiki_markup_cat = "[[Kategorie:" .. cat .. "|"
		if modell ~= "" then
			wiki_markup_cat = wiki_markup_cat .. modell
		else			
			wiki_markup_cat = wiki_markup_cat .. "{{PAGENAME}}"
		end			
			
		wiki_markup_cat = wiki_markup_cat .. "]]"
	end

	return wiki_markup_cat
		
end

function p.extractLinkTarget(frame)
--[[  
	Ersten Link-Target aus Wiki-Markup extrahieren. 
	Wenn kein Wiki-Link enthalten ist, dann gesamten Text zurückgeben.
	Parameter: 
	*	Wiki-Markup
]]
	return p._extractLinkTarget(frame.args[1])
end

--[[ Hilfsfunktionen
----------------------
]]

function p._extractLinkTarget(wiki_markup)
--[[  
	Ersten Link-Target aus Wiki-Markup extrahieren. 
	Wenn kein Wiki-Link enthalten ist, dann gesamten Text zurückgeben.
	Parameter: 
	*	Wiki-Markup
]]
	local link_target = wiki_markup
	local pos_startlink = mw.ustring.find(wiki_markup, "[[", 1, true)
	if pos_startlink ~= nil then
		local pos_endlink = mw.ustring.find(wiki_markup, "]]", pos_startlink+1, true)
		if pos_endlink ~= nil then
			local pos_pipe = mw.ustring.find(wiki_markup, "|", pos_startlink+1, true)
			if pos_pipe ~= nil and pos_pipe < pos_endlink then
				link_target = mw.ustring.sub(wiki_markup, pos_startlink+2, pos_pipe-1)
			else
				link_target = mw.ustring.sub(wiki_markup, pos_startlink+2, pos_endlink-1)
			end
		end
	end
	return link_target
end

return p