Difference between revisions of "Module:CountryAdjectiveDemonym"

From blackwiki
Jump to navigation Jump to search
blackwiki>BrownHairedGirl
(Created page with 'local CountryNameDemonym = { } local CountryNameDemonymDataLoaded = false local CountryNameDemonymNameCounter = 0 local countryAdjectivesToNounsTable = { } lo...')
 
blackwiki>BrownHairedGirl
(args)
Line 33: Line 33:
 
-- then return that prefix
 
-- then return that prefix
 
-- Otherwise just return an empty string
 
-- Otherwise just return an empty string
function CountryNameDemonym.countryPrefixThe(s)
+
function CountryNameDemonym.countryPrefixThe(frame)
 +
local s = frame.args[1]
 +
if not CountryNameDemonymDataLoaded then
 +
CountryNameDemonymDoLoadData()
 +
end
 
if (countriesPrefixedByTheTable[s] == true) then
 
if (countriesPrefixedByTheTable[s] == true) then
 
return "the "
 
return "the "
Line 41: Line 45:
  
  
function CountryNameDemonym.getCountryFromAdjective(s)
+
function CountryNameDemonym.getCountryFromAdjective(frame)
 +
local s = frame.args[1]
 
if not CountryNameDemonymDataLoaded then
 
if not CountryNameDemonymDataLoaded then
 
CountryNameDemonymDoLoadData()
 
CountryNameDemonymDoLoadData()
Line 49: Line 54:
  
  
function CountryNameDemonym.getAdjectiveFromCountry(s)
+
function CountryNameDemonym.getAdjectiveFromCountry(frame)
 +
local s = frame.args[1]
 
if not CountryNameDemonymDataLoaded then
 
if not CountryNameDemonymDataLoaded then
 
CountryNameDemonymDoLoadData()
 
CountryNameDemonymDoLoadData()
Line 56: Line 62:
 
end
 
end
  
function CountryNameDemonym.stripThe(s)
+
function CountryNameDemonym.stripThe(frame)
 +
local s = frame.args[1]
 
if s == nil then
 
if s == nil then
 
return nil
 
return nil

Revision as of 12:57, 7 October 2019

Documentation for this module may be created at Module:CountryAdjectiveDemonym/doc

local CountryNameDemonym = { }

local CountryNameDemonymDataLoaded = false

local CountryNameDemonymNameCounter = 0

local countryAdjectivesToNounsTable = {
}
local countryNounstoAdjectivesTable  = {
}

local countriesPrefixedByTheTable = {
}

function CountryNameDemonymDoLoadData()
	countriesPrefixedByTheTable = mw.loadData( 'Module:CountryNameDemonym/the' )
	countryNounstoAdjectivesTable = mw.loadData( 'Module:CountryNameDemonym/adjectives' )
	local myCounter = 0
	local myNoun, myAdj
	for myNoun, myAdj in pairs(countryNounstoAdjectivesTable) do
		countryAdjectivesToNounsTable[myAdj] = myNoun
		myCounter = myCounter + 1
	end
	CountryNameDemonymNameCounter = myCounter
	CountryNameDemonymDataLoaded = true
	return myCounter
end


-- ############### Publicly accesible functions #######################

-- if the country name is prefixed by "the" in running text,
-- then return that prefix
-- Otherwise just return an empty string
function CountryNameDemonym.countryPrefixThe(frame)
	local s = frame.args[1]
	if not CountryNameDemonymDataLoaded then
		CountryNameDemonymDoLoadData()
	end
	if (countriesPrefixedByTheTable[s] == true) then
		return "the "
	end
	return ""
end


function CountryNameDemonym.getCountryFromAdjective(frame)
	local s = frame.args[1]
	if not CountryNameDemonymDataLoaded then
		CountryNameDemonymDoLoadData()
	end
	return countryAdjectivesToNounsTable[s]
end


function CountryNameDemonym.getAdjectiveFromCountry(frame)
	local s = frame.args[1]
	if not CountryNameDemonymDataLoaded then
		CountryNameDemonymDoLoadData()
	end
	return countryNounstoAdjectivesTable[s]
end

function CountryNameDemonym.stripThe(frame)
	local s = frame.args[1]
	if s == nil then
		return nil
	end
	if mw.ustring.match( s, "^[T]he Gambia$") ~= nil then
		return s
	end
	local stripped = mw.ustring.gsub(s, "^[tT]he ", "")
	return stripped
end


return CountryNameDemonym