Module:Country extract

From Jurassic Outpost Encyclopedia
Revision as of 16:40, 5 June 2016 by Part Time Hero (talk | contribs) (1 revision imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

local p = {} -- -- to enable us to replicate the current functioning of CountryAbbr and CountryAbbr2 -- We need to deal with -- 1 alternative names ISO 3166 should do that -- 2 {{<name>}} -- 3 [ [<name>] ] -- 4 [ [<name>|<junk>] ] -- 5 [ [image:flag of <country>.[svg|gif|png|jpg]|\d+px] ] --

function p.extractCountry(frame)

  local string= mw.ustring.toNFC (frame.args[1])
  local match=nil;
  match = mw.ustring.match(string, "Flag of ([^\.]*)")
  if (match) then 
     return match
  end 

-- () for Cocos (Keeling) Islands -- ' For People's -- . for U.S. etc.

  match = mw.ustring.match(string, "(%u[%a\(\)\.' -]+)")
  if (match == "Image") then
      string = mw.ustring.gsub(string, match, "")
      match = mw.ustring.match(string, "[\|\[](%u[%a\(\)\.' -]+)")
  end
  if (match == "20px") then
      string = mw.ustring.gsub(string, match, "")
      match = mw.ustring.match(string, "\[(%u[%a\(\)\.' -]+)")
  end 
  if (match) then 
     return match
  end
  return  string

end

--[[


]]

function p.extractSubdivision(frame)

  local string= mw.ustring.toNFC (frame.args[1])
  local match=nil;

-- Needed for Template:Country data Greenland,

  match = mw.ustring.match(string, "Flag of ([^\.]*)")
  if (match) then 
     return match
  end 

-- . needed for Washington D.C. -- ' for cote d'azur -- leading ' for 'Aden -- ‘ and trailing ' for Şan‘ā'

  match = mw.ustring.match(string, "('?[%u][%a'‘ \.\,-]+[%a\.'\d]+)")
  if (match) then 
     return match
  end
  return  string

end


return p