Module:Nomenclature

local p = {} local cargo = mw.ext.cargo local translation = require('Module:Translation') local expgame = require('Module:Exp Game') local utilsCode = require('Module:UtilsCode') local utilsLanguage = require('Module:UtilsLanguage') local utilsTable = require('Module:UtilsTable')

--Create an empty table with headers function p.CreateTable --Table structure local resultTable = mw.html.create("table") :addClass("wikitable") :css{ ["margin"] = "1em", ["font-size"] = "95%", }:done --Global header local headerRow = mw.html.create("tr"):done local headerContent = mw.html.create("th") :wikitext(" Names in Other Regions ") :attr("colspan", "4") :css{ ["font-size"] = "110%", }:done headerRow:node(headerContent) resultTable:node(headerRow) --Individual headers --Language headerRow = mw.html.create("tr"):done headerContent = mw.html.create("th") :wikitext("Language") :attr("colspan", "2"):done headerRow:node(headerContent) --Name headerContent = mw.html.create("th") :wikitext("Name"):done headerRow:node(headerContent) --Meaning headerContent = mw.html.create("th") :wikitext("Meaning"):done headerRow:node(headerContent) resultTable:node(headerRow) return resultTable end

function p.CreateRows(output, term) local cargoData = translation.fetchTranslations(term) p.SortTranslations(cargoData) for key, value in pairs(cargoData) do		p.ProcessRow(output, cargoData, value) end return output end

function p.ProcessRow(output, cargoData, value) local keysToRemove = {} local games = {} local meanings = {} local tr = mw.html.create("tr"):done local td = mw.html.create("td") :wikitext(utilsLanguage.CodeToFlag(value["language"])):done tr:node(td) td = mw.html.create("td") :wikitext(utilsLanguage.CodeToLanguage(value["language"])):done tr:node(td) td = mw.html.create("td"):done for key2, value2 in pairs(cargoData) do		if value["language"] == value2["language"] and value["translation"] == value2["translation"] then table.insert(games, value2["game"]) table.insert(keysToRemove, key2) end end table.insert(meanings, value["meaning"]) td:wikitext(value["translation"] .. " " .. expgame.Display(games)) games = {} for key2, value2 in pairs(cargoData) do		if value["language"] == value2["language"] and value["translation"] ~= value2["translation"] then for key3, value3 in pairs(cargoData) do				if value2["language"] == value3["language"] and value2["translation"] == value3["translation"] then table.insert(games, value3["game"]) table.insert(keysToRemove, key3) end end table.insert(meanings, value2["meaning"]) td:wikitext(" " .. value2["translation"] .. " " .. expgame.Display(games)) end end tr:node(td) td = mw.html.create("td"):done local first = true for key2, value2 in pairs(meanings) do		if not utilsCode.IsEmpty(value2) then if first then td:wikitext(value2) first = false else td:wikitext(" " .. value2) end else td:wikitext(" —") end end tr:node(td) output:node(tr) for key2, value2 in pairs(keysToRemove) do		cargoData[value2] = nil end end

function p.SortTranslations(translations) local lookup = utilsTable.hash(utilsLanguage.GetCodeSortOrder) table.sort(translations, function (a,b)			return (lookup[a.language] or 0) < (lookup[b.language] or 0)		end	) end

function p.Main( frame ) local args = frame:getParent.args local resultTable = p.CreateTable local resultTable = p.CreateRows(resultTable, "Dynalfos") return resultTable end

return p