Module:CountryAdjectiveDemonym
Appearance
| This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing. |
| This module is currently protected from editing. See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected. |
| This module depends on the following other modules: |
| This Lua module is used on approximately 89,000 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. |
Usage
{{#invoke:CountryAdjectiveDemonym|function_name}}
See also
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(s)
if (countriesPrefixedByTheTable[s] == true) then
return "the "
end
return ""
end
function CountryNameDemonym.getCountryFromAdjective(s)
if not CountryNameDemonymDataLoaded then
CountryNameDemonymDoLoadData()
end
return countryAdjectivesToNounsTable[s]
end
function CountryNameDemonym.getAdjectiveFromCountry(s)
if not CountryNameDemonymDataLoaded then
CountryNameDemonymDoLoadData()
end
return countryNounstoAdjectivesTable[s]
end
function CountryNameDemonym.stripThe(s)
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