Difference between revisions of "Module:CountryAdjectiveDemonym"
Jump to navigation
Jump to search
blackwiki>BrownHairedGirl (diag) |
blackwiki>BrownHairedGirl (update variable names) |
||
| Line 45: | Line 45: | ||
| − | function CountryNameDemonym. | + | function CountryNameDemonym.getCountryFromDemonym(frame) |
local s = frame.args[1] | local s = frame.args[1] | ||
if not CountryNameDemonymDataLoaded then | if not CountryNameDemonymDataLoaded then | ||
CountryNameDemonymDoLoadData() | CountryNameDemonymDoLoadData() | ||
end | end | ||
| − | local retval | + | local retval = countryAdjectivesToNounsTable[s] |
| − | + | if retval == nil then | |
| − | + | return "" | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | retval | ||
| − | |||
| − | |||
| − | |||
| − | |||
end | end | ||
return retval | return retval | ||
| Line 75: | Line 58: | ||
| − | function CountryNameDemonym. | + | function CountryNameDemonym.getDemonymFromCountry(frame) |
local s = frame.args[1] | local s = frame.args[1] | ||
if not CountryNameDemonymDataLoaded then | if not CountryNameDemonymDataLoaded then | ||
CountryNameDemonymDoLoadData() | CountryNameDemonymDoLoadData() | ||
end | end | ||
| − | + | local retval = countryNounstoAdjectivesTable[s] | |
| + | if retval == nil then | ||
| + | return "" | ||
| + | end | ||
| + | return retval | ||
end | end | ||
| Line 86: | Line 73: | ||
local s = frame.args[1] | local s = frame.args[1] | ||
if s == nil then | if s == nil then | ||
| − | return | + | return "" |
end | end | ||
if mw.ustring.match( s, "^[T]he Gambia$") ~= nil then | if mw.ustring.match( s, "^[T]he Gambia$") ~= nil then | ||
Revision as of 14:46, 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.getCountryFromDemonym(frame)
local s = frame.args[1]
if not CountryNameDemonymDataLoaded then
CountryNameDemonymDoLoadData()
end
local retval = countryAdjectivesToNounsTable[s]
if retval == nil then
return ""
end
return retval
end
function CountryNameDemonym.getDemonymFromCountry(frame)
local s = frame.args[1]
if not CountryNameDemonymDataLoaded then
CountryNameDemonymDoLoadData()
end
local retval = countryNounstoAdjectivesTable[s]
if retval == nil then
return ""
end
return retval
end
function CountryNameDemonym.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 CountryNameDemonym