Module:Aircraft by nationality explained

local p =

--Similar to : 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').exists if exists then return ''..disp..'' else return '

'..disp..'' endend

--checks for existance & returns tracking if missingfunction checkparent(colon, name, sortkey) local exists = mw.title.new(name, 'Category').exists if not exists then return ''..sortkey..'' end return end

----Main --

function p.catnav(frame) local currtitle = mw.title.getCurrentTitle local namespace = currtitle.nsText local testcases = (currtitle.subpageText

'testcases') local colon = if namespace ~= 'Category' then colon = ':' end local args = frame:getParent.args local nation = args['nation'] --live -- local nation = frame.args['nation'] --direct from cat local pagename = currtitle.baseText local trackingcats = local parentcats = local countries = --determine category type local nation_airtitle = nil --autodetected from air title local adj, civmilair = string.match(pagename, '^(.+) (civil) aircraft$') --assume civ if civmilair

nil then adj, civmilair = string.match(pagename, '^(.+) (military) aircraft$') --mil end if civmilair

nil then civmilair, nation_airtitle = string.match(pagename, '^(Aircraft) manufactured in ([^%/]+)$') --air end if civmilair

nil then civmilair = string.match(pagename, '^(International) aircraft$') --int (special case) end if civmilair

nil then if namespace

'Category' or testcases then trackingcats[3] = '' end return table.concat(trackingcats) end local CivMilAir = civmilair:gsub("^%l", string.upper) --proceed according to category type local civmil = (civmilair ~= 'Aircraft' and civmilair ~= 'International') if civmil then --if DNE, find it via the title adjective if nation

nil or (nation and nation

) then for _, kv in pairs (countries) do if kv[2]

adj then nation = kv[1] break end end end --tracking cats 1 & 2; parent cat 1 if nation

nil or (nation and nation

) then trackingcats[1] = 'N' elseif nation

'International' then local basename = 'International aircraft' --static: no check/tracking needed if CivMilAir

'Civil' then parentcats[1] = 'Civil' else parentcats[1] = 'Military aircraft, International' end else local basename = 'Aircraft manufactured in '..nation trackingcats[2] = checkparent(colon, basename, 'Q') parentcats[1] = ''..CivMilAir..' aircraft, '..nation..'' end --parent 2 static: no check/tracking needed if CivMilAir

'Civil' then parentcats[2] = '' else parentcats[2] = '' end elseif civmilair

'Aircraft' then if nation

nil or (nation and nation

) then nation = nation_airtitle --use title if DNE end --air parent 1 local nation_sortkey = string.gsub(nation, '^the ', ) parentcats[1] = ''..nation_sortkey..'' --static: no check/tracking needed --air tracking/parent 2 local basename = 'Aviation in '..nation trackingcats[2] = checkparent(colon, basename, 'R') --TODO: update cat description text & inc sortkeys parentcats[2] = 'Aircraft' else --if civmilair

'International' then parentcats[1] = '' --static: no check/tracking needed end local heading1 = CivMilAir..' aircraft' --assume civmil local heading2 = civmilair..' aircraft' --assume civmil if not civmil then heading1 = 'Aircraft' heading2 = 'aircraft' end local sep = ' • ' local catnav = '

-\n'.. '\n'.. ""..heading1.." by nationality of original manufacturer
".. 'International joint ventures
' for _, kv in pairs (countries) do local the_c = kv[1] local a = kv[2] local c = (string.gsub(the_c, '^the ', )) local basename = a..' '..civmilair..' aircraft' --assume civmil if not civmil then basename = 'Aircraft manufactured in '..the_c end catnav = catnav..catlink(basename, c)..sep end catnav = mw.text.trim(catnav, sep) catnav = catnav..'\n'.. '
\n'.. '
' return catnav..table.concat(trackingcats)..table.concat(parentcats)end

return p