@@ -1,8 +1,12 @@
1−{-# LANGUAGE DeriveDataTypeable, OverloadedStrings, NoImplicitPrelude, PatternGuards #-}
1+{-# LANGUAGE DeriveDataTypeable, OverloadedStrings, NoImplicitPrelude
2+ , DeriveGeneric, DeriveAnyClass, PatternGuards, FlexibleInstances
3+ , MultiParamTypeClasses, StandaloneDeriving, CPP #-}
4+{-# OPTIONS_GHC -fconstraint-solver-iterations=10 #-}
25-- | This file is generated from the Wikipedia page
36-- <http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2>
47module Data.CountryCodes.ISO31661 (
58 CountryCode(..)
9+ , countryList
610 , fromMText
711 , fromText
812 , fromMName
@@ -12,12 +16,20 @@ module Data.CountryCodes.ISO31661 (
1216) where
1317
1418import Control.Applicative (pure)
15−import Data.Aeson
16−import Data.Typeable
17−import qualified Data.Text as T
18−import Prelude (Show,Read,Eq,Ord,Bounded,Enum,error,($),(++),Maybe(..),(.),fail)
19+import Control.DeepSeq (NFData(..))
20+import Data.Aeson
21+import Data.Typeable
22+import Data.Text as T
23+import GHC.Generics
24+import Prelude (Show,Read,Eq,Ord,Bounded,Enum,error,($),(++),Maybe(..),(.),fail,seq)
25+import Text.Shakespeare.I18N
26+#ifdef BACKEND
27+import Data.OpenApi
28+import Test.QuickCheck.Arbitrary
29+import Test.QuickCheck.Arbitrary.Generic
30+#endif
1931
20−data CountryCode =
32+data CountryCode =
2133 AD
2234 | AE
2335 | AF
@@ -267,7 +279,19 @@ data CountryCode =
267279 | ZA
268280 | ZM
269281 | ZW
270− deriving (Show,Read,Eq,Ord,Bounded,Enum,Typeable)
282+ -- Added these non standard codes that occur in
283+ -- travolutionary database
284+ -- https://typeable.atlassian.net/browse/B2H-796
285+ | XA
286+ | AN
287+ | XK
288+ | XC
289+ | WE
290+ deriving (Show,Read,Eq,Ord,Bounded,Enum,Typeable, Generic
291+#ifdef BACKEND
292+ , ToSchema
293+#endif
294+ )
271295
272296-- | Maybe get the CountryCode from the text code.
273297fromMText :: T.Text -> Maybe CountryCode
@@ -520,6 +544,11 @@ fromMText "YT" = Just YT
520544fromMText "ZA" = Just ZA
521545fromMText "ZM" = Just ZM
522546fromMText "ZW" = Just ZW
547+fromMText "XA" = Just XA
548+fromMText "AN" = Just AN
549+fromMText "XK" = Just XK
550+fromMText "XC" = Just XC
551+fromMText "WE" = Just WE
523552fromMText _ = Nothing
524553
525554-- | Get the CountryCode from the text code. Errors if the code is unknown
@@ -779,6 +808,11 @@ toText YT = "YT"
779808toText ZA = "ZA"
780809toText ZM = "ZM"
781810toText ZW = "ZW"
811+toText XA = "XA"
812+toText AN = "AN"
813+toText XK = "XK"
814+toText XC = "XC"
815+toText WE = "WE"
782816
783817-- | Maybe get the code from the user readable name.
784818fromMName :: T.Text -> Maybe CountryCode
@@ -1031,6 +1065,11 @@ fromMName "Mayotte" = Just YT
10311065fromMName "South Africa" = Just ZA
10321066fromMName "Zambia" = Just ZM
10331067fromMName "Zimbabwe" = Just ZW
1068+fromMName "Canary Islands" = Just XA
1069+fromMName "Netherlands Antilles" = Just AN
1070+fromMName "Kosovo" = Just XK
1071+fromMName "Ceuta" = Just XC
1072+fromMName "West Bank" = Just WE
10341073fromMName _ = Nothing
10351074
10361075-- | Get the CountryCode from the user readable name. Errors if the name is unknown
@@ -1289,12 +1328,295 @@ toName YE = "Yemen"
12891328toName YT = "Mayotte"
12901329toName ZA = "South Africa"
12911330toName ZM = "Zambia"
1292−toName ZW = "Zimbabwe"-- | to json: as a simple string
1331+toName ZW = "Zimbabwe"
1332+toName XA = "Canary Islands"
1333+toName AN = "Netherlands Antilles"
1334+toName XK = "Kosovo"
1335+toName XC = "Ceuta"
1336+toName WE = "West Bank"
1337+
1338+-- | list of names sorted by alphabetical order, with country code
1339+-- this is ready to be used in a yesod selectField, for example
1340+countryList :: [(T.Text,CountryCode)]
1341+countryList = [("Afghanistan",AF)
1342+ ,("Albania",AL)
1343+ ,("Algeria",DZ)
1344+ ,("American Samoa",AS)
1345+ ,("Andorra",AD)
1346+ ,("Angola",AO)
1347+ ,("Anguilla",AI)
1348+ ,("Antarctica",AQ)
1349+ ,("Antigua and Barbuda",AG)
1350+ ,("Argentina",AR)
1351+ ,("Armenia",AM)
1352+ ,("Aruba",AW)
1353+ ,("Australia",AU)
1354+ ,("Austria",AT)
1355+ ,("Azerbaijan",AZ)
1356+ ,("Bahrain",BH)
1357+ ,("Bangladesh",BD)
1358+ ,("Barbados",BB)
1359+ ,("Belarus",BY)
1360+ ,("Belgium",BE)
1361+ ,("Belize",BZ)
1362+ ,("Benin",BJ)
1363+ ,("Bermuda",BM)
1364+ ,("Bhutan",BT)
1365+ ,("Bolivia",BO)
1366+ ,("Bosnia and Herzegovina",BA)
1367+ ,("Botswana",BW)
1368+ ,("Bouvet Island",BV)
1369+ ,("Brazil",BR)
1370+ ,("British Indian Ocean Territory",IO)
1371+ ,("British Virgin Islands",VG)
1372+ ,("Brunei",BN)
1373+ ,("Bulgaria",BG)
1374+ ,("Burkina Faso",BF)
1375+ ,("Burundi",BI)
1376+ ,("Cambodia",KH)
1377+ ,("Cameroon",CM)
1378+ ,("Canada",CA)
1379+ ,("Cape Verde",CV)
1380+ ,("Caribbean Netherlands",BQ)
1381+ ,("Cayman Islands",KY)
1382+ ,("Central African Republic",CF)
1383+ ,("Chad",TD)
1384+ ,("Chile",CL)
1385+ ,("China",CN)
1386+ ,("Christmas Island",CX)
1387+ ,("Cocos (Keeling) Islands",CC)
1388+ ,("Collectivity of Saint Martin",MF)
1389+ ,("Colombia",CO)
1390+ ,("Comoros",KM)
1391+ ,("Cook Islands",CK)
1392+ ,("Costa Rica",CR)
1393+ ,("Croatia",HR)
1394+ ,("Cuba",CU)
1395+ ,("Curaçao",CW)
1396+ ,("Cyprus",CY)
1397+ ,("Czech Republic",CZ)
1398+ ,("Côte d'Ivoire",CI)
1399+ ,("Democratic Republic of the Congo",CD)
1400+ ,("Denmark",DK)
1401+ ,("Djibouti",DJ)
1402+ ,("Dominica",DM)
1403+ ,("Dominican Republic",DO)
1404+ ,("East Timor",TL)
1405+ ,("Ecuador",EC)
1406+ ,("Egypt",EG)
1407+ ,("El Salvador",SV)
1408+ ,("Equatorial Guinea",GQ)
1409+ ,("Eritrea",ER)
1410+ ,("Estonia",EE)
1411+ ,("Ethiopia",ET)
1412+ ,("Falkland Islands",FK)
1413+ ,("Faroe Islands",FO)
1414+ ,("Federated States of Micronesia",FM)
1415+ ,("Fiji",FJ)
1416+ ,("Finland",FI)
1417+ ,("France",FR)
1418+ ,("French Guiana",GF)
1419+ ,("French Polynesia",PF)
1420+ ,("French Southern and Antarctic Lands",TF)
1421+ ,("Gabon",GA)
1422+ ,("Georgia (country)",GE)
1423+ ,("Germany",DE)
1424+ ,("Ghana",GH)
1425+ ,("Gibraltar",GI)
1426+ ,("Greece",GR)
1427+ ,("Greenland",GL)
1428+ ,("Grenada",GD)
1429+ ,("Guadeloupe",GP)
1430+ ,("Guam",GU)
1431+ ,("Guatemala",GT)
1432+ ,("Guernsey",GG)
1433+ ,("Guinea",GN)
1434+ ,("Guinea-Bissau",GW)
1435+ ,("Guyana",GY)
1436+ ,("Haiti",HT)
1437+ ,("Heard Island and McDonald Islands",HM)
1438+ ,("Honduras",HN)
1439+ ,("Hong Kong",HK)
1440+ ,("Hungary",HU)
1441+ ,("Iceland",IS)
1442+ ,("India",IN)
1443+ ,("Indonesia",ID)
1444+ ,("Iran",IR)
1445+ ,("Iraq",IQ)
1446+ ,("Isle of Man",IM)
1447+ ,("Israel",IL)
1448+ ,("Italy",IT)
1449+ ,("Jamaica",JM)
1450+ ,("Japan",JP)
1451+ ,("Jersey",JE)
1452+ ,("Jordan",JO)
1453+ ,("Kazakhstan",KZ)
1454+ ,("Kenya",KE)
1455+ ,("Kiribati",KI)
1456+ ,("Kuwait",KW)
1457+ ,("Kyrgyzstan",KG)
1458+ ,("Laos",LA)
1459+ ,("Latvia",LV)
1460+ ,("Lebanon",LB)
1461+ ,("Lesotho",LS)
1462+ ,("Liberia",LR)
1463+ ,("Libya",LY)
1464+ ,("Liechtenstein",LI)
1465+ ,("Lithuania",LT)
1466+ ,("Luxembourg",LU)
1467+ ,("Macau",MO)
1468+ ,("Madagascar",MG)
1469+ ,("Malawi",MW)
1470+ ,("Malaysia",MY)
1471+ ,("Maldives",MV)
1472+ ,("Mali",ML)
1473+ ,("Malta",MT)
1474+ ,("Marshall Islands",MH)
1475+ ,("Martinique",MQ)
1476+ ,("Mauritania",MR)
1477+ ,("Mauritius",MU)
1478+ ,("Mayotte",YT)
1479+ ,("Mexico",MX)
1480+ ,("Moldova",MD)
1481+ ,("Monaco",MC)
1482+ ,("Mongolia",MN)
1483+ ,("Montenegro",ME)
1484+ ,("Montserrat",MS)
1485+ ,("Morocco",MA)
1486+ ,("Mozambique",MZ)
1487+ ,("Myanmar",MM)
1488+ ,("Namibia",NA)
1489+ ,("Nauru",NR)
1490+ ,("Nepal",NP)
1491+ ,("Netherlands",NL)
1492+ ,("New Caledonia",NC)
1493+ ,("New Zealand",NZ)
1494+ ,("Nicaragua",NI)
1495+ ,("Niger",NE)
1496+ ,("Nigeria",NG)
1497+ ,("Niue",NU)
1498+ ,("Norfolk Island",NF)
1499+ ,("North Korea",KP)
1500+ ,("Northern Mariana Islands",MP)
1501+ ,("Norway",NO)
1502+ ,("Oman",OM)
1503+ ,("Pakistan",PK)
1504+ ,("Palau",PW)
1505+ ,("Panama",PA)
1506+ ,("Papua New Guinea",PG)
1507+ ,("Paraguay",PY)
1508+ ,("Peru",PE)
1509+ ,("Philippines",PH)
1510+ ,("Pitcairn Islands",PN)
1511+ ,("Poland",PL)
1512+ ,("Portugal",PT)
1513+ ,("Puerto Rico",PR)
1514+ ,("Qatar",QA)
1515+ ,("Republic of Ireland",IE)
1516+ ,("Republic of Macedonia",MK)
1517+ ,("Republic of the Congo",CG)
1518+ ,("Romania",RO)
1519+ ,("Russia",RU)
1520+ ,("Rwanda",RW)
1521+ ,("Réunion",RE)
1522+ ,("Saint Barthélemy",BL)
1523+ ,("Saint Helena, Ascension and Tristan da Cunha",SH)
1524+ ,("Saint Kitts and Nevis",KN)
1525+ ,("Saint Lucia",LC)
1526+ ,("Saint Pierre and Miquelon",PM)
1527+ ,("Saint Vincent and the Grenadines",VC)
1528+ ,("Samoa",WS)
1529+ ,("San Marino",SM)
1530+ ,("Saudi Arabia",SA)
1531+ ,("Senegal",SN)
1532+ ,("Serbia",RS)
1533+ ,("Seychelles",SC)
1534+ ,("Sierra Leone",SL)
1535+ ,("Singapore",SG)
1536+ ,("Sint Maarten",SX)
1537+ ,("Slovakia",SK)
1538+ ,("Slovenia",SI)
1539+ ,("Solomon Islands",SB)
1540+ ,("Somalia",SO)
1541+ ,("South Africa",ZA)
1542+ ,("South Georgia and the South Sandwich Islands",GS)
1543+ ,("South Korea",KR)
1544+ ,("South Sudan",SS)
1545+ ,("Spain",ES)
1546+ ,("Sri Lanka",LK)
1547+ ,("State of Palestine",PS)
1548+ ,("Sudan",SD)
1549+ ,("Suriname",SR)
1550+ ,("Svalbard and Jan Mayen",SJ)
1551+ ,("Swaziland",SZ)
1552+ ,("Sweden",SE)
1553+ ,("Switzerland",CH)
1554+ ,("Syria",SY)
1555+ ,("São Tomé and Príncipe",ST)
1556+ ,("Taiwan",TW)
1557+ ,("Tajikistan",TJ)
1558+ ,("Tanzania",TZ)
1559+ ,("Thailand",TH)
1560+ ,("The Bahamas",BS)
1561+ ,("The Gambia",GM)
1562+ ,("Togo",TG)
1563+ ,("Tokelau",TK)
1564+ ,("Tonga",TO)
1565+ ,("Trinidad and Tobago",TT)
1566+ ,("Tunisia",TN)
1567+ ,("Turkey",TR)
1568+ ,("Turkmenistan",TM)
1569+ ,("Turks and Caicos Islands",TC)
1570+ ,("Tuvalu",TV)
1571+ ,("Uganda",UG)
1572+ ,("Ukraine",UA)
1573+ ,("United Arab Emirates",AE)
1574+ ,("United Kingdom",GB)
1575+ ,("United States",US)
1576+ ,("United States Minor Outlying Islands",UM)
1577+ ,("United States Virgin Islands",VI)
1578+ ,("Uruguay",UY)
1579+ ,("Uzbekistan",UZ)
1580+ ,("Vanuatu",VU)
1581+ ,("Vatican City",VA)
1582+ ,("Venezuela",VE)
1583+ ,("Vietnam",VN)
1584+ ,("Wallis and Futuna",WF)
1585+ ,("Western Sahara",EH)
1586+ ,("Yemen",YE)
1587+ ,("Zambia",ZM)
1588+ ,("Zimbabwe",ZW)
1589+ ,("Åland Islands",AX)
1590+ ,("Canary Islands", XA)
1591+ ,("Netherlands Antilles",AN)
1592+ ,("Kosovo",XK)
1593+ ,("Ceuta",XC)
1594+ ,("West Bank",WE)
1595+ ]
1596+
1597+-- | to json: as a simple string
12931598instance ToJSON CountryCode where
1294− toJSON =toJSON . toText
1599+ toJSON = toJSON . toText
12951600
12961601-- | from json: as a simple string
12971602instance FromJSON CountryCode where
12981603 parseJSON (String s)
12991604 | Just a <- fromMText s=pure a
1300− parseJSON _ =fail "CountryCode"
1605+ parseJSON _ = fail "CountryCode"
1606+
1607+deriving instance ToJSONKey CountryCode
1608+deriving instance FromJSONKey CountryCode
1609+
1610+-- | show user readable name, in English (ignoring locale for now)
1611+instance RenderMessage master CountryCode where
1612+ renderMessage _ _ = toName
1613+
1614+-- | Allow the deep evaluation of CountryCode with `deepseq`
1615+instance NFData CountryCode where
1616+ rnf a = a `seq` ()
1617+
1618+#ifdef BACKEND
1619+instance Arbitrary CountryCode where
1620+ arbitrary = genericArbitrary
1621+ shrink = genericShrink
1622+#endif