Difference between revisions of "Module:CountryAdjectiveDemonym/sandbox"
Jump to navigation
Jump to search
blackwiki>BrownHairedGirl (create, using "CountryAdjectiveDemonym") |
blackwiki>BrownHairedGirl (fix sub-module names) |
||
| Line 8: | Line 8: | ||
function CountryAdjectiveDemonymDoLoadData() | function CountryAdjectiveDemonymDoLoadData() | ||
| − | countriesPrefixedByTheTable = mw.loadData( 'Module: | + | countriesPrefixedByTheTable = mw.loadData( 'Module:CountryNameDemonym/the' ) |
| − | countryNounstoAdjectivesTable = mw.loadData( 'Module: | + | countryNounstoAdjectivesTable = mw.loadData( 'Module:CountryNameDemonym/adjectives' ) |
local myCounter = 0 | local myCounter = 0 | ||
local myNoun, myAdj | local myNoun, myAdj | ||
Revision as of 21:46, 7 October 2019
Documentation for this module may be created at Module:CountryAdjectiveDemonym/sandbox/doc
local CountryAdjectiveDemonym = { }
local CountryAdjectiveDemonymDataLoaded = false
local countryAdjectivesToNounsTable = { }
local countryNounstoAdjectivesTable = { }
local countriesPrefixedByTheTable = { }
function CountryAdjectiveDemonymDoLoadData()
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
CountryAdjectiveDemonymDataLoaded = 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 CountryAdjectiveDemonym.countryPrefixThe(frame)
local s = frame.args[1]
if not CountryAdjectiveDemonymDataLoaded then
CountryAdjectiveDemonymDoLoadData()
end
if (countriesPrefixedByTheTable[s] == true) then
return "the "
end
return ""
end
function CountryAdjectiveDemonym.getCountryFromDemonym(frame)
local s = frame.args[1]
if not CountryAdjectiveDemonymDataLoaded then
CountryAdjectiveDemonymDoLoadData()
end
local retval = countryAdjectivesToNounsTable[s]
if retval == nil then
return ""
end
return retval
end
function CountryAdjectiveDemonym.getDemonymFromCountry(frame)
local s = frame.args[1]
if not CountryAdjectiveDemonymDataLoaded then
CountryAdjectiveDemonymDoLoadData()
end
local retval = countryNounstoAdjectivesTable[s]
if retval == nil then
return ""
end
return retval
end
function CountryAdjectiveDemonym.stripThe(frame)
local s = frame.args[1]
if s == nil then
return ""
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 CountryAdjectiveDemonym