This is an old revision of this page, as edited by Gonnym(talk | contribs) at 16:35, 2 August 2021(added function which finds the country name in a full text string). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.Revision as of 16:35, 2 August 2021 by Gonnym(talk | contribs)(added function which finds the country name in a full text string)
This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing.
This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing.
This module depends on the following other modules:
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()endforadjective,nouninpairs(countryAdjectivesToNounsTable)doifstring.find(s,adjective)orstring.find(s,noun)thenreturnnounendendendfunctionCountryAdjectiveDemonym.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