This Lua module is used on many pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them.
localCountryAdjectiveDemonym={}localCountryAdjectiveDemonymDataLoaded=falselocalcountryAdjectivesToNounsTable={}localcountryNounsToAdjectivesTable={}localcountryDemonymsToNounsTable={}localcountryNounsToDemonymsTable={}localcountriesPrefixedByTheTable={}functionCountryAdjectiveDemonymDoLoadData()countriesPrefixedByTheTable=mw.loadData('Module:CountryAdjectiveDemonym/The')countryNounsToAdjectivesTable=mw.loadData('Module:CountryAdjectiveDemonym/Adjectives')countryNounsToDemonymsTable=mw.loadData('Module:CountryAdjectiveDemonym/Demonyms')localmyNoun,myAdjective-- first, load the adjectives tableformyNoun,myAdjectiveinpairs(countryNounsToAdjectivesTable)docountryAdjectivesToNounsTable[myAdjective]=myNounend-- Now load the denomyms tablelocalmyDemonymformyNoun,myDemonyminpairs(countryNounsToDemonymsTable)docountryDemonymsToNounsTable[myDemonym]=myNounendCountryAdjectiveDemonymDataLoaded=truereturnend-- ############### Publicly accesible functions #######################-- if the country name is prefixed by "the" in running text,-- then return that prefix-- Otherwise just return an empty stringfunctionCountryAdjectiveDemonym.countryPrefixThe(frame)locals=frame.args[1]ifnotCountryAdjectiveDemonymDataLoadedthenCountryAdjectiveDemonymDoLoadData()endif(countriesPrefixedByTheTable[s]==true)thenreturn"the "endreturn""endfunctionCountryAdjectiveDemonym.getCountryFromAdjective(frame)locals=frame.args[1]ifnotCountryAdjectiveDemonymDataLoadedthenCountryAdjectiveDemonymDoLoadData()endlocalretval=countryAdjectivesToNounsTable[s]ifretval==nilthenifs=="Georgia (country)"thenreturnsendreturn""endreturnretvalendfunctionCountryAdjectiveDemonym.getCountryFromString(frame)locals=frame.args[1]ifnotCountryAdjectiveDemonymDataLoadedthenCountryAdjectiveDemonymDoLoadData()endlocalsimilarLongerNouns=mw.loadData('Module:CountryAdjectiveDemonym/LongerNouns')foradjective,nouninpairs(countryAdjectivesToNounsTable)doifstring.find(s,adjective)orstring.find(s,noun)thenforlongerNoun,nameToUseinpairs(similarLongerNouns)doifstring.find(s,longerNoun)thenreturnnameToUseendendreturnnounendendendfunctionCountryAdjectiveDemonym.getCountryFromDemonym(frame)locals=frame.args[1]ifnotCountryAdjectiveDemonymDataLoadedthenCountryAdjectiveDemonymDoLoadData()endlocalretval=countryDemonymsToNounsTable[s]ifretval==nilthenretval=countryAdjectivesToNounsTable[s]endifretval==nilthenreturn""endreturnretvalendfunctionCountryAdjectiveDemonym.getAdjectiveFromCountry(frame)locals=frame.args[1]ifnotCountryAdjectiveDemonymDataLoadedthenCountryAdjectiveDemonymDoLoadData()endlocalretval=countryNounsToAdjectivesTable[s]ifretval==nilthenreturn""endreturnretvalendfunctionCountryAdjectiveDemonym.getDemonymFromCountry(frame)locals=frame.args[1]ifnotCountryAdjectiveDemonymDataLoadedthenCountryAdjectiveDemonymDoLoadData()endlocalretvalretval=countryNounsToDemonymsTable[s]ifretval==nilthenretval=countryNounsToAdjectivesTable[s]endifretval==nilthenreturn""endreturnretvalendfunctionCountryAdjectiveDemonym.stripThe(frame)locals=frame.args[1]ifs==nilthenreturn""endifmw.ustring.match(s,"^[T]he Gambia$")~=nilthenreturnsendlocalstripped=mw.ustring.gsub(s,"^[tT]he ","")returnstrippedendreturnCountryAdjectiveDemonym