Module:Country2nationality: Difference between revisions
https://sandbox.indicwiki.org/>MusikBot II m Protected "Module:Country2nationality": High-risk template or module: 40330 transclusions (more info) ([Edit=Require template editor access] (indefinite) [Move=Require template editor access] (indefinite)) |
m 1 revision imported |
||
| (2 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local data = { | local data = { -- override list | ||
AFRICA = "African", | |||
ANTARCTICA = "Antarctic", | |||
ASIA = "Asian", | |||
BRITISHHONGKONG = "British Hong Kong", | |||
BRITISHINDIA = "British India", | |||
AUSTROHUNGARIANEMPIRE = "Austrian", | |||
CATALONIA = "Catalan", | |||
CZECHOSLOVAKIA = "Czech", | |||
DUTCHEASTINDIES = "Dutch East Indian", | |||
EASTGERMANY = "East German", | |||
EUROPE = "European", | |||
FPRYUGOSLAVIA = "Yugoslavian", | |||
GERMANDEMOCRATICREPUBLIC = "East German", | |||
GERMANEMPIRE = "German", | |||
KURDISTAN = "Kurdish", | |||
NAZIGERMANY = "German", | |||
NORTHAMERICA = "North American", | |||
OCEANIA = "Oceanian", | |||
PAHLAVIIRAN = "Iranian", | |||
REPUBLICOFVIETNAM = "Vietnamese", | |||
RHODESIA = "Rhodesian", | |||
RUSSIANEMPIRE = "Russian", | |||
SOUTHAMERICA = "South American", | |||
SOUTHVIETNAM = "Vietnamese", | |||
SOVIETUNION = "Soviet", | |||
WESTGERMANY = "West German", | |||
UNITEDARABREPUBLIC = "Arab", | |||
USSR = "Soviet", | |||
YUGOSLAVIA = "Yugoslavian" | |||
} | } | ||
function p.c2n(country) | function p.c2n(name, nocat) | ||
country = mw.ustring.gsub( mw. | name = mw.text.trim(name) | ||
local iso = require("Module:ISO 3166").code({country}) | local country = mw.ustring.gsub(name, "^St. ", "Saint ") | ||
if # | country = mw.ustring.gsub(mw.ustring.gsub(country, "SFR ", ""), " SSR", "" ) | ||
return require("Module:Iso2nationality").i2n( | local iso = require("Module:ISO 3166") | ||
elseif data[ | local isocode = iso.code({country, nocat = nocat}) | ||
return data[mw.ustring. | if #isocode == 2 or #isocode == 6 then -- valid code | ||
return require("Module:Iso2nationality").i2n(isocode) | |||
elseif data[iso.strip(country)] then -- in override list | |||
return data[iso.strip(country)] | |||
elseif mw.ustring.find(name, " SSR") then -- most SSRs are already in adjective form | |||
return country | |||
elseif string.sub(isocode,1,2)=="[[" then | |||
return name..isocode | |||
end | end | ||
return | return name | ||
end | end | ||
p[''] = function (frame) return p.c2n(frame.args[1]) end | p[''] = function (frame) return p.c2n(frame.args[1], frame.args.nocat) end | ||
return p | return p | ||
Latest revision as of 07:05, 4 April 2025
Documentation for this module may be created at Module:Country2nationality/doc
local p = {}
local data = { -- override list
AFRICA = "African",
ANTARCTICA = "Antarctic",
ASIA = "Asian",
BRITISHHONGKONG = "British Hong Kong",
BRITISHINDIA = "British India",
AUSTROHUNGARIANEMPIRE = "Austrian",
CATALONIA = "Catalan",
CZECHOSLOVAKIA = "Czech",
DUTCHEASTINDIES = "Dutch East Indian",
EASTGERMANY = "East German",
EUROPE = "European",
FPRYUGOSLAVIA = "Yugoslavian",
GERMANDEMOCRATICREPUBLIC = "East German",
GERMANEMPIRE = "German",
KURDISTAN = "Kurdish",
NAZIGERMANY = "German",
NORTHAMERICA = "North American",
OCEANIA = "Oceanian",
PAHLAVIIRAN = "Iranian",
REPUBLICOFVIETNAM = "Vietnamese",
RHODESIA = "Rhodesian",
RUSSIANEMPIRE = "Russian",
SOUTHAMERICA = "South American",
SOUTHVIETNAM = "Vietnamese",
SOVIETUNION = "Soviet",
WESTGERMANY = "West German",
UNITEDARABREPUBLIC = "Arab",
USSR = "Soviet",
YUGOSLAVIA = "Yugoslavian"
}
function p.c2n(name, nocat)
name = mw.text.trim(name)
local country = mw.ustring.gsub(name, "^St. ", "Saint ")
country = mw.ustring.gsub(mw.ustring.gsub(country, "SFR ", ""), " SSR", "" )
local iso = require("Module:ISO 3166")
local isocode = iso.code({country, nocat = nocat})
if #isocode == 2 or #isocode == 6 then -- valid code
return require("Module:Iso2nationality").i2n(isocode)
elseif data[iso.strip(country)] then -- in override list
return data[iso.strip(country)]
elseif mw.ustring.find(name, " SSR") then -- most SSRs are already in adjective form
return country
elseif string.sub(isocode,1,2)=="[[" then
return name..isocode
end
return name
end
p[''] = function (frame) return p.c2n(frame.args[1], frame.args.nocat) end
return p