Module:Aircraft by nationality

local p = {}--Similar to {{LinkCatIfExists2}}: make a piped link to a category, if it exists;--if it doesn't exist, just display the greyed link title without linkingfunction catlink( name, disp )name = mw.text.trim(name or '')disp = mw.text.trim(disp or '')local grey = '#888'local exists = mw.title.new( name, 'Category' ).existsif exists thenreturn '[[:Category:'..name..'|'..disp..']]'elsereturn '<span style="color:'..grey..'">'..disp..'</span>'endend--checks for existance & returns tracking [[Category:Aircraft catnav missing parent]] if missingfunction checkparent( colon, name, sortkey )local exists = mw.title.new( name, 'Category' ).existsif not exists thenreturn '[['..colon..'Category:Aircraft catnav missing parent|'..sortkey..']]'endreturn ''end--[[==========================================================================]]--[[                                   Main                                   ]]--[[==========================================================================]]function p.catnav( frame )local currtitle = mw.title.getCurrentTitle()local namespace = currtitle.nsTextlocal testcases = (currtitle.subpageText == 'testcases')local colon = ''if namespace ~= 'Category' then colon = ':' endlocal args = frame:getParent().argslocal nation = args['nation'] --live {{Template}}--local nation = frame.args['nation'] --direct {{#invoke:}} from catlocal pagename = currtitle.baseTextlocal trackingcats = {'', --[1] placeholder for [[Category:Aircraft catnav missing parameter]] (civ/mil)'', --[2] placeholder for [[Category:Aircraft catnav missing parent]] (civ/mil/air)'', --[3] placeholder for [[Category:Aircraft catnav failed to generate navbox]] !(civ/mil/air)}local parentcats = {'', --[1] placeholder for [[Category:Aircraft manufactured in {{{nation}}}]] (civ) or --  [[Category:International aircraft]] (mil)--  [[Category:Aircraft by country]] (air)'', --[2] placeholder for [[Category:Civil aircraft]] (civ) or--  [[Category:Military aircraft by country]] (mil)--  [[Category:Aircraft in <nation>]] (air)}local countries = {--{ 'the Country Name', 'Adjectival' },-- 'the' gets removed as needed{ 'Algeria', 'Algerian' },{ 'Argentina', 'Argentine' },{ 'Australia', 'Australian' },{ 'Austria', 'Austrian' },{ 'Austria and Austria-Hungary', 'Austrian and Austro-Hungarian' }, --[[Category:Austrian and Austro-Hungarian civil aircraft]]{ 'Belgium', 'Belgian' },{ 'Brazil', 'Brazilian' },{ 'Bulgaria', 'Bulgarian' },{ 'Canada', 'Canadian' },{ 'Chile', 'Chilean' },{ 'China', 'Chinese' },{ 'Colombia', 'Colombian' },{ 'Cyprus', 'Cypriot' },{ 'the Czech Republic and Czechoslovakia', 'Czech and Czechoslovakian' },{ 'Denmark', 'Danish' },{ 'Egypt', 'Egyptian' },{ 'Estonia', 'Estonian' },{ 'Finland', 'Finnish' },{ 'France', 'French' },{ 'Georgia (country)', 'Georgian' }, --only 1 [[WP:AIR]] adj precedent: [[Category:Georgian aircraft designers]] (doesn't disambig){ 'East Germany', 'East German' },{ 'Germany', 'German' },{ 'Greece', 'Greek' },{ 'Hungary', 'Hungarian' },{ 'India', 'Indian' },{ 'Indonesia', 'Indonesian' },{ 'Iran', 'Iranian' },{ 'Israel', 'Israeli' },{ 'Italy', 'Italian' },{ 'Japan', 'Japanese' },{ 'Jordan', 'Jordanian' },{ 'Latvia', 'Latvian' },{ 'Lithuania', 'Lithuanian' },{ 'Malaysia', 'Malaysian' },{ 'Mexico', 'Mexican' },{ 'the Netherlands', 'Dutch' },{ 'New Zealand', 'New Zealand' },{ 'Norway', 'Norwegian' },{ 'the State of Palestine', 'Palestinian' },{ 'Pakistan', 'Pakistani' },{ 'Peru', 'Peruvian' },{ 'the Philippines', 'Philippine' },{ 'Poland', 'Polish' },{ 'Portugal', 'Portuguese' },{ 'the Republic of China', 'Republic of China' },{ 'Romania', 'Romanian' },{ 'Russia', 'Russian' },{ 'Saudi Arabia', 'Saudi Arabian' },{ 'Singapore', 'Singaporean' }, --[[Category:Singaporean military aircraft]]{ 'Slovakia', 'Slovak' },{ 'Slovenia', 'Slovenian' },{ 'South Africa', 'South African' },{ 'South Korea', 'South Korean' },{ 'the Soviet Union', 'Soviet' },{ 'Soviet Union and CIS', 'Soviet and Russian' },{ 'Spain', 'Spanish' },{ 'Sweden', 'Swedish' },{ 'Switzerland', 'Swiss' },{ 'Taiwan', 'Taiwanese' },{ 'Thailand', 'Thai' },{ 'Turkey', 'Turkish' },{ 'the United Arab Emirates', 'Emirati' },{ 'the United Kingdom', 'British' },{ 'the United States', 'United States' },{ 'Ukraine', 'Ukrainian' },{ 'Vietnam', 'Vietnamese' },{ 'Yugoslavia', 'Yugoslav' },{ 'Yugoslavia and Serbia', 'Yugoslav and Serbian' },}--determine category typelocal nation_airtitle = nil --autodetected from air titlelocal adj, civmilair = string.match(pagename, '^(.+) (civil) aircraft$') --assume civif civmilair == nil thenadj, civmilair = string.match(pagename, '^(.+) (military) aircraft$') --milendif civmilair == nil thencivmilair, nation_airtitle = string.match(pagename, '^(Aircraft) manufactured in ([^%/]+)$') --airendif civmilair == nil thencivmilair = string.match(pagename, '^(International) aircraft$') --int (special case)endif civmilair == nil then if namespace == 'Category' or testcases then trackingcats[3] = '[['..colon..'Category:Aircraft catnav failed to generate navbox]]' end return table.concat(trackingcats)endlocal CivMilAir = civmilair:gsub("^%l", string.upper)--proceed according to category typelocal civmil = (civmilair ~= 'Aircraft' and civmilair ~= 'International')if civmil then--if {{{nation}}} DNE, find it via the title adjectiveif nation == nil or (nation and nation == '') thenfor _, kv in pairs (countries) doif kv[2] == adj thennation = kv[1]breakendendend--tracking cats 1 & 2; parent cat 1if nation == nil or (nation and nation == '') thentrackingcats[1] = '[['..colon..'Category:Aircraft catnav missing parameter|N]]'elseif nation == 'International' thenlocal basename = 'International aircraft' --static: no check/tracking neededif CivMilAir == 'Civil' thenparentcats[1] = '[['..colon..'Category:'..basename..'|Civil]]'elseparentcats[1] = '[['..colon..'Category:'..basename..'|Military aircraft, International]]'endelselocal basename = 'Aircraft manufactured in '..nationtrackingcats[2] = checkparent(colon, basename, 'Q')parentcats[1] = '[['..colon..'Category:'..basename..'| '..CivMilAir..' aircraft, '..nation..']]'end--parent 2 static: no check/tracking neededif CivMilAir == 'Civil' thenparentcats[2] = '[['..colon..'Category:Civil aircraft]]'elseparentcats[2] = '[['..colon..'Category:Military aircraft by country]]'endelseif civmilair == 'Aircraft' thenif nation == nil or (nation and nation == '') thennation = nation_airtitle --use title if {{{nation}}} DNEend--air parent 1local nation_sortkey = string.gsub(nation, '^the ', '')parentcats[1] = '[['..colon..'Category:Aircraft by country|'..nation_sortkey..']]' --static: no check/tracking needed--air tracking/parent 2local basename = 'Aviation in '..nationtrackingcats[2] = checkparent(colon, basename, 'R') --TODO: update cat description text & inc {{Milairnd}} sortkeysparentcats[2] = '[['..colon..'Category:'..basename..'|Aircraft]]'else --if civmilair == 'International' thenparentcats[1] = '[['..colon..'Category:Aircraft by country| ]]' --static: no check/tracking neededendlocal heading1 = CivMilAir..' aircraft' --assume civmillocal heading2 = civmilair..' aircraft' --assume civmilif not civmil thenheading1 = 'Aircraft'heading2 = 'aircraft'endlocal sep = ' • 'local catnav =  '{| class="toccolours" cellpadding="2" cellspacing="0" style="margin:3px auto; border: 1px solid; font-size:95%;  align="center"\n'..'|-\n'..'| style="text-align:center;" |\n'.."'''"..heading1.." by nationality of original manufacturer'''<br/> "..'[[:Category:International '..heading2..'|International joint ventures]]<br/>'for _, kv in pairs (countries) dolocal the_c = kv[1]local a = kv[2]local c = (string.gsub(the_c, '^the ', ''))local basename = a..' '..civmilair..' aircraft' --assume civmilif not civmil thenbasename = 'Aircraft manufactured in '..the_cendcatnav = catnav..catlink(basename, c)..sependcatnav = mw.text.trim(catnav, sep)catnav = catnav..'\n'..'|}\n'..'<br/>'return catnav..table.concat(trackingcats)..table.concat(parentcats)endreturn p