Module:TerrainCats

local TerrainCategories = {} -- Wikitext lists --local List = require('Dev:List') -- Helper function local ctTrans = require('Module:CTtrans').climateTerrainString

local function Category( category, sortkey ) if sortkey == nil then sortkey = '' else sortkey = '|' .. sortkey end return string.format('%s'..'Category:%s%s]]', '[[', category, sortkey) end

local function makeCategory( inputText ) if ctTrans(inputText) ~= "" then return Category(           ('Creatures found in %s'):format(ctTrans(inputText))        ) else return nil end end

function TerrainCategories.TerrainCats( frame ) local output = {} local splitText = mw.text.split(mw.ustring.lower(frame.args[1]), '%s*%p%s*') for _,v in ipairs(splitText) do       if v == "any land" then table.insert(output, makeCategory('desert')) table.insert(output, makeCategory('forest')) table.insert(output, makeCategory('hills')) table.insert(output, makeCategory('marshes')) table.insert(output, makeCategory('mountains')) table.insert(output, makeCategory('plains')) elseif v == "any space" then table.insert(output, makeCategory('wildspace')) table.insert(output, makeCategory('phlogiston')) else table.insert(output, makeCategory(v)) end end return table.concat(output) end

return TerrainCategories