Module:phi-placelist

Hello, you have come here looking for the meaning of the word Module:phi-placelist. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:phi-placelist, but we will also tell you about its etymology, its characteristics and you will know how to say Module:phi-placelist in singular and plural. Everything you need to know about the word Module:phi-placelist you have here. The definition of the word Module:phi-placelist will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:phi-placelist, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

This module is used by {{list:places in the Philippines/en}}.

Data modules


-- Author: ]

-- This is the maximum number of levels/divisions
local maxLevel = 10

-----------------

local function getKeysOfTable(table)
	return require("Module:table").keysToList(table);
end

-----------------


-- Main function
local function getTableFromData( args )
	
	local inputtedDivisions = {} -- save here the inputted divisions, in order of less specific to more specific
	
	local level = 0
	while ( level < maxLevel ) do
		
		argLevel = args
		if argLevel ~= nil then  -- get all positional arguments from 0 to `maxLevel`
			inputtedDivisions = argLevel
		end
		level = level + 1
	end
	
	-- get the division from data modules
	local list = {} 
	local _region = ""
	for i, v in ipairs( inputtedDivisions ) do
		if (i == 1 and #inputtedDivisions == 1) then  -- if the first and only the first one, get from region data module
			list = require("Module:phi-placelist/data/" .. v)
		elseif (i == 1) then --if the first one, it is the region, store it
			_region = v
		elseif (i == 2) then --if the second one, get from data module
			
			-- list = require("Module:phi-placelist/data/" .. _region .. "/" .. v)
			--=====
			-- TEMPORARY SOLUTION for Sulu since it doesn't have a region,
			-- remove this once Sulu has a designated regoon
			if _region == "Sulu" then
				list = require("Module:phi-placelist/data/" .. _region)
			else 
				list = require("Module:phi-placelist/data/" .. _region .. "/" .. v)
			end
			--=====
			
		elseif (i == #inputtedDivisions and args == "hyponyms") then  
			--special case if hyponyms, get the "hyponyms" table
			list = list
		else 
			list = list
		end
		
	end
	
	-- error check so that the last inputted parameter is one division up
	if type(list) ~= "table" then
		error(inputtedDivisions .. " has no divisions.")
	end
	
	-- get the keys from the data module & prepare for template call
	local divisionName = list
	if args == "hyponyms" then 
		divisionName = "specific places"
	end
	
	local excludesText = nil
	if list ~= nil then
		excludesText =  list
	end
	
	-- erase from list before processing the final list
	list = nil
	list = nil
	list = nil
	
	-- get final list
	local finalList = nil
	if args == "hyponyms" then
		finalList = list 
	else 
		finalList = getKeysOfTable(list)
	end
	
    return finalList, inputtedDivisions, divisionName, excludesText
	
end

local a = {}


-- for use in the definition lines
function a.linksInDefinition( frame )

	local args = frame:getParent().args
	
	local templateToCall = args
	if templateToCall == nil then
		templateToCall = "coordinate terms"
	end
	

    -- get table
	local finalList, inputtedDivisions, divisionName, excludesText = getTableFromData(args)


	-- prepare parameters for the {{coordinate terms}} (or others) template call
	table.insert(finalList, 1, "en") -- the language parameter
	
	finalList = divisionName .. " of " .. inputtedDivisions -- the label parameter
	
	if excludesText ~= nil then
		finalList = finalList .. " <small>(excluding " .. excludesText .. ")</small>"
	end
	
	return frame:expandTemplate{ title = templateToCall , args = finalList }
	
end


-- for use in `See also` headings
function a.linksInSeeAlso( frame )
	
	local args = frame:getParent().args
	
    -- get table
	local finalList, inputtedDivisions, divisionName, excludesText = getTableFromData(args)
	
	-- prepare parameters for the {{col3}} template call
	table.insert(finalList, 1, "en") -- the language parameter

	local label = divisionName .. " of " .. inputtedDivisions -- label
	
	
	if excludesText ~= nil then
		label = label .. " <small>(excluding " .. excludesText .. ")</small>"
	end
	
	-- no need to use {{q}} to reduce lua usage
	return "(''" .. label .. "''): " .. frame:expandTemplate{ title = "col3" , args = finalList }
	
end


return a;