Giter VIP home page Giter VIP logo

stefangabos / world_countries Goto Github PK

View Code? Open in Web Editor NEW
1.3K 51.0 374.0 11.97 MB

Constantly updated lists of world countries and their associated alpha-2, alpha-3 and numeric country codes as defined by the ISO 3166 standard, available in CSV, JSON , PHP, SQL and XML formats, in multiple languages and with national flags included; also available are the ISO 3166-2 codes of provinces/ states associated with the countries

Home Page: http://stefangabos.github.io/world_countries/

License: Other

PHP 100.00%
countries flags mysql national-flags iso-3166-1 sql multilingual json csv xml

world_countries's Introduction

zebrajs

World countries  Tweet

available in multiple languages, in CSV, JSON, PHP, SQL and XML formats, with associated codes as defined by the ISO 3166 standard, and with national flags included; also available are the ISO 3166-2 codes used for identifying the principal subdivisions (e.g., provinces or states) of all countries coded in ISO 3166-1

npm Total Monthly JSDelivr License

Constantly updated lists of world countries, territories and areas of geographical interest, with associated alpha-2, alpha-3 and numeric codes as defined by the ISO 3166-1 standard, published and maintained by the International Organization for Standardization, available in CSV, JSON, PHP, SQL and XML formats, in multiple languages and with national flags included. Also available are the ISO 3166-2 codes used for identifying the principal subdivisions (e.g., provinces or states) of all countries coded in ISO 3166-1.

In the language folders (inside data/countries) you will find files named in two different ways.
Here's what you will find in each of them:

File names Content
world.* Files named like this contain all the 249 countries, territories, and areas of geographical interest that have an officially assigned ISO 3166-1 code.
countries.* Files named like this contain the 193 sovereign states (commonly referred to as countries) that are members of the United Nations (UN) .

Note that there are 206 sovereign states in the world, the 11 states that are missing from the countries list being the ones having their sovereignty disputed. See the list of sovereign states with information on their status and recognition of their sovereignty.

The files contain:

  • the ISO 3166-1 numeric country codes
  • the ISO 3166 official short names in English1
  • the ISO 3166-1 alpha-2 two-letter country codes2
  • the ISO 3166-1 alpha-3 three-letter country codes2

1 for other languages the country names are in that particular language
2 ISO 3166-1 alpha codes are uppercase but this library provides them in lowercase

The lists are currently available in 35 languages:

  • Arabic
  • Armenian
  • Basque
  • Bulgarian
  • Chinese (Simplified)
  • Chinese (Traditional)
  • Croatian
  • Czech
  • Danish
  • Dutch
  • English
  • Esperanto
  • Estonian
  • Farsi
  • Finnish
  • French
  • German
  • Greek
  • Hungarian
  • Italian
  • Japanese
  • Korean
  • Lithuanian
  • Norwegian
  • Polish
  • Portuguese
  • Romanian
  • Russian
  • Serbian
  • Slovak
  • Slovenian
  • Spanish
  • Swedish
  • Thai
  • Ukrainian

The language folders are named based on the ISO 639-1 standard.

ISO 3166-2 codes

The project also tries to be a comprehensive and up-to-date source for ISO 3166-2 which defines codes for identifying the principal subdivisions (e.g., provinces or states) of all countries coded in ISO 3166-1.

The purpose of ISO 3166-2 is to establish an international standard of short and unique alphanumeric codes to represent the relevant administrative divisions and dependent territories of all countries in a more convenient and less ambiguous form than their full names. Each complete ISO 3166-2 code consists of two parts, separated by a hyphen:

US-TX for Texas, USA

The first part is the ISO 3166-1 alpha-2 code of the country; The second part is a string of up to three alphanumeric characters, which is usually obtained from national sources and stems from coding systems already in use in the country concerned, but may also be developed by the ISO itself. Each complete ISO 3166-2 code can then be used to uniquely identify a country subdivision in a global context.

The list is available in CSV, JSON, PHP, SQL and XML formats in the data/subdivisions folder and the CSV one looks like this:

US,US-AL,Alabama
US,US-AK,Alaska
US,US-AZ,Arizona
US,US-AR,Arkansas
US,US-CA,California
US,US-CO,Colorado

The starting point of this list was the ISO 3166-2 Subdivision Code list provided by IP2Location but this one will be maintained by the community.

🎂 Support the development of this project

Your support means a lot and it keeps me motivated to keep working on open source projects.
If you like this project please ⭐ it by clicking on the star button at the top of the page.
If you are feeling generous, you can buy me a coffee by donating through PayPal, or you can become a sponsor.
Either way - Thank you! 🎉

Star it on GitHub Donate

Installation

The lists are available as a npm package. To install it use:

# the "--save" argument adds the plugin as a dependency in packages.json
npm install world_countries_lists --save

You can install the lists via Composer

composer require stefangabos/world_countries

Alternatively, you can load data from JSDelivr CDN like this:

<script src="https://cdn.jsdelivr.net/npm/world_countries_lists@latest/data/countries/en/countries.json"></script>

Or

download a customized build.

Data formats

SQL

Excerpt from the data/countries/en/countries.sql file:

(250,'fr','fra','France'),
(266,'ga','gab','Gabon'),
(270,'gm','gmb','Gambia'),
(268,'ge','geo','Georgia'),
(276,'de','deu','Germany'),
(288,'gh','gha','Ghana'),
(300,'gr','grc','Greece'),
(308,'gd','grd','Grenada'),

CSV

Excerpt from the data/countries/en/countries.csv file:

250,fr,fra,France
266,ga,gab,Gabon
270,gm,gmb,Gambia
268,ge,geo,Georgia
276,de,deu,Germany
288,gh,gha,Ghana
300,gr,grc,Greece
308,gd,grd,Grenada

JSON

Excerpt from the data/countries/en/countries.json file:

{"id":250,"alpha2":"fr","alpha3":"fra","name":"France"},
{"id":266,"alpha2":"ga","alpha3":"gab","name":"Gabon"},
{"id":270,"alpha2":"gm","alpha3":"gmb","name":"Gambia"},
{"id":268,"alpha2":"ge","alpha3":"geo","name":"Georgia"},
{"id":276,"alpha2":"de","alpha3":"deu","name":"Germany"},
{"id":288,"alpha2":"gh","alpha3":"gha","name":"Ghana"},
{"id":300,"alpha2":"gr","alpha3":"grc","name":"Greece"},
{"id":308,"alpha2":"gd","alpha3":"grd","name":"Grenada"},

Here's a little helper function for searching for a specific country's data

The helper function assumes that the JSON with the countries data is associated with a variable named countries which is in the same scope as the function

The helper function is to be used with the non-combined data sets.
For the combined data sets you can write the function yourself.

//  returns an object with the sought country's data if the search yields a result
//  returns undefined if no results could be found or if argument is incorrect
function search_country(query) {

    // if argument is not valid return false
    if (undefined === query.id && undefined === query.alpha2 && undefined === query.alpha3) return undefined;

        // iterate over the array of countries
	return countries.filter(function(country) {

        // return country's data if
        return (
            // we are searching by ID and we have a match
            (undefined !== query.id && parseInt(country.id, 10) === parseInt(query.id, 10))
            // or we are searching by alpha2 and we have a match
            || (undefined !== query.alpha2 && country.alpha2 === query.alpha2.toLowerCase())
            // or we are searching by alpha3 and we have a match
            || (undefined !== query.alpha3 && country.alpha3 === query.alpha3.toLowerCase())
        )

    // since "filter" returns an array we use pop to get just the data object
    }).pop()

}

Usage

search_country({id: 250})
search_country({alpha2: 'fr'})
search_country({alpha3: 'fra'})

TypeScript

Typings are available (source):

import { Country, LanguageCode, TranslatedCountry } from 'world_countries_lists'

PHP

Excerpt from the data/countries/en/countries.php file:

250 => array('id' => 250, 'alpha2' => 'fr', 'alpha3' => 'fra', 'name' => 'France'),
266 => array('id' => 266, 'alpha2' => 'ga', 'alpha3' => 'gab', 'name' => 'Gabon'),
270 => array('id' => 270, 'alpha2' => 'gm', 'alpha3' => 'gmb', 'name' => 'Gambia'),

Here's a little helper function for searching for a specific country's data

The helper function is to be used with the non-combined data sets.
For the combined data sets you can write the function yourself.

//  this function assumes that you have done this:
$countries = require 'path/to/countries.php';

//  returns an array with the sought country's data if the search yields a result
//  returns false if no results could be found or if argument is incorrect
function search_country($query) {

    // make the countries available in the function
    global $countries;

    // if argument is not valid return false
    if (!isset($query['id']) && !isset($query['alpha2']) && !isset($query['alpha3'])) return false;

    // iterate over the array of countries
    $result = array_filter($countries, function($country) use ($query) {

        // return country's data if
        return (
            // we are searching by ID and we have a match
            (isset($query['id']) && $country['id'] == $query['id'])
            // or we are searching by alpha2 and we have a match
            || (isset($query['alpha2']) && $country['alpha2'] == strtolower($query['alpha2']))
            // or we are searching by alpha3 and we have a match
            || (isset($query['alpha3']) && $country['alpha3'] == strtolower($query['alpha3']))
        );

    });

    // since "array_filter" returns an array we use pop to get just the data object
    // we return false if a result was not found
    return empty($result) ? false : array_pop($result);

}

Usage

search_country(array('id' => 250));
search_country(array('alpha2' => 'fr'));
search_country(array('alpha3' => 'fra'));

XML

Excerpt from the data/countries/en/countries.xml file:

<country id="250" alpha2="fr" alpha3="fra" name="France"/>
<country id="266" alpha2="ga" alpha3="gab" name="Gabon"/>
<country id="270" alpha2="gm" alpha3="gmb" name="Gambia"/>
<country id="268" alpha2="ge" alpha3="geo" name="Georgia"/>
<country id="276" alpha2="de" alpha3="deu" name="Germany"/>
<country id="288" alpha2="gh" alpha3="gha" name="Ghana"/>
<country id="300" alpha2="gr" alpha3="grc" name="Greece"/>
<country id="308" alpha2="gd" alpha3="grd" name="Grenada"/>

Flags

The package also contains the national flags of each country as a 16x16, 24x24, 32x32, 48x48, 64x64 and 128x128 PNG images. The image files are named using the ISO 3166-1-alpha-2 code of the country they represent, for easily pairing flags with countries.

Flag images are also available as single JSON files, one for each of the available sizes, containing all flag images as data-uri

Data sources

Country names in all languages are taken from Wikipedia.

world_countries's People

Contributors

bfischer1121 avatar edy-dev avatar parikshit-hooda avatar rd-pingedpng avatar respencer avatar spyridonas avatar stefangabos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

world_countries's Issues

Flags

Hi there,

The country flags for the Congo (cg) and the Democratic Republic of Congo (cd) have been inverted for the 16x16 and 24x24, pictures.

Typo in readme causing error

In the readme.md there are a few error's causing error's in the code.
search_county(array('id' => 250}); search_county(array('alpha2' => 'fr'}); search_county(array('alpha3' => 'fra'});

=>

  1. This should be search_country instead of county!
  2. This should be )); instead of });
  3. $countries = require 'path/to/countries.php'; does not work, you need just require 'path/to/countries.php';
    This one already creates the $countries variable.
  4. Your sample code does not seem to work with the _combined file.

The sample php code also does not work, I get following error:
Fatal error: Uncaught TypeError: array_filter(): Argument #1 ($array) must be of type array, int given in C:\xampp\htdocs\account.php:214 Stack trace: #0 C:\xampp\htdocs\account.php(214): array_filter(1, Object(Closure)) #1 C:\xampp\htdocs\account.php(222): search_country(Array) #2 {main} thrown in C:\xampp\htdocs\account.php on line 214

I tried both loading the _combined as the language specific file, neither solves the issue.
/vendor/stefangabos/world_countries/data/countries/en/countries.php

  • Maybe add an example how to use it using composer?

What about CountryCode xk Kosovo it is missing

I use this as backend JSON and we have a new frontend package. It lead to the error that CountryCode xk does not exist. Seems that's Kosovo. I guess it should be part of the list, right?

Custom download - flags images corrupted

On the web page, if i download the master (first download button), there is no issue.

But if i request a partial download, just selecting what i need, like, for example 64x64 flags only, then i hit download, i would get the .png files corrupted (can't be read).

This issue is not only for 64x64 but for any custom/partial download of flags in .png format.

Add currencies

These are amazing lists! Thank you so much for those. Do you think it is reasonable to add currencies as well? We can take translations from Android.

Groenland

Hey please add Groenland to your database :)

French :
Groenland | GL | GRL | 304

Rename Belarus

Please rename "Белоруссия" to "Беларусь"

States request

Hi, I live your code, it's so helpful.
Are you considering to add states as well? I really need US and Canada and I don't want to use another package if not necessary.

Thanks!

Add Finnish as language

Hi there, we want to use Country names in "Finnish" language. Would it be possible to add this language?

Regards

Add new language: basque

Hi:

This project has been very useful for us to get the translations of the country names for a project.

Can you please add basque (eu) translations? The wikipedia page is up to date with official basque names, and if someone is missing I will update it right away:

JSON with data URI flags

Many thanks for this stuff, it came really handy to me.

It would be nice if you could provide a JSON file that would contain flags as data URI strings, or perhaps just an additional JSON with alpha2 + data URI properties. This way they could be downloaded in one request instead of many. For example, in a current project we needed a country dropdown with flags and that would mean 193 individual image request.

image

I manually created such JSON in a web controller and added to a cache, but an "official" version would be nice.

Change data source to official EU data

As I understand actually you take the data from Wikipedia. There may be some of "poetic freedom" inside.
Is it not more convenient to use official EU data (or to verify with them). They are well maintained and contain some more data (e. g. the capital and the currency, currency subunit and currency code) and all 24 EU languages.
http://publications.europa.eu/code/en/en-5000500.htm
http://publications.europa.eu/code/de/de-5000500.htm
http://publications.europa.eu/code/fr/fr-5000500.htm
http://publications.europa.eu/code/lt/lt-5000500.htm
...

How to add flags inside to database

Hello!

Sorry about my question maybe it will be out of logic but how can i added the flags inside to database you privide ? Also flags i downloaded from your code.

Thank you very much!

Swaziland is in between changing its country name

I am not sure if this will effect the alpha codes for a country name change. But Swaziland is currently renaming its self to eSwatini. A few companies here have taken on the new name like Swazi Mobile is now eSwatini Mobile.

Separate simplified and traditional Chinese versions needed

Some of the countries have different translation in simplified and traditional Chinese, thus should be collected separately. For example, Antigua and Barbuda(zh-tw:安地卡及巴布達; zh-cn:安提瓜和巴布达) and Cyprus(zh-tw:賽普勒斯;zh-cn:塞浦路斯).
Wikipedia provides many kinds of Chinese variation, including Mainland China Chinese(zh-cn), Taiwan Chinese(zh-tw), Hong Kong Chinese(zh-hk)(not to be confused w/ Cantonese), Macau Chinese(zh-mo), Singapore Chinese(zh-sg) and Malaysia Chinese(zh-my). Mainly zh-cn and zh-tw are needed, but finishing all these versions is appreciated.

Unable to download Flags

Hi @stefangabos, I was trying to download a CSV of Flags in either 16x16 or 24x24 but they won't download. Any ideas on what could be wrong?

Cheers,
Hakim

alpha-2 and alpha-3 data violates ISO 3166-1:2020

Chapter 5.1 says:

LATIN CAPITAL LETTER A through LATIN CAPITAL LETTER Z; Code elements alpha-2 and alpha-3 are formed with LETTERS,

All country codes in data is wrong because it does not use uppercase letters, but lowercase letters. Lowercase letters are used with ISO 639 for languages only.

Please correct the data.

Armenian country and subdivision names

Hi!
I'd like to contribute the Armenian translations for country and also (some) subdivision names. In #60 you mention you do not take any direct contributions for country names but rather fetching them from Wikipedia. If that's the case, this is the page that can be used for it https://hy.wikipedia.org/wiki/ISO_3166-1. Please suggest if the format is not suitable, or otherwise if the direct PR with translation is needed.
Also, any idea how to maintain subdivision name translations?

Kosovo is missing in world list

FIrst of all, thanks for work!

I've recently used your world list to translate a list of around 250 country codes.
But I've noticed that the country code "xk" for "Kosovo" didn't get translated and after further research I found, that Kosovo and it's code are not represented in your world list based on ISO-3166.

Opening up the german wikipedia page for ISO-3166 it is there, but not on the englisch wikipedia page it doesn't seem to be there.

Notice, that Kosovo doesn't have a numeric ISO-3166 code

I'm not sure, if not containing Kosovo is intended, but in case not, I wanted to notify you of my findings.

An unknown country code KS

I've met a verid country code KS for a couple of airports like LYPT and BKPR. According to wikipedia, both of them located in Serbia or Kosovo. According to wikipedia again, the country code of Serbia is RS and there seems no any valid code for Kosovo except for user-assigned code which is XK.

Inconsistency in language folder names

Hello,
if you use "en" for English I suppose that the name of the language folders are set according to the language iso_639_1 code.
In that case, Japanese is 'ja' and not 'jp'

Anarctica is not a country

I think some penguin partisans have hacked your computer.

In seriousness, there is a lack of trimmed down list of countries.

The ISO should not be a trusted authority on sovereignty or nationality.

I'm taking your list and trimming out anything that isn't a part of the UN: http://www.un.org/en/member-states/

I can submit a pull request if you want to include it. There is surprisingly a missing dataset of UN member states.

Looks like St Helen is missing

Hi,

the country(?) St Helen is missing:
Saint Helena (and/or) Ascension Island (and/or) Tristan da Cunha

ISO 3166-1
Alpha-2 code: SH
Alpha-3 code: SHN
Numeric code: 654

ISO 3166-2 Province/State/Region Offical Breakout of Countires

I am not sure what kind of scripting you have to bread this out, but what about adding the ISO 3166-2 as a seperate data file

Pulling data from the official ISO website is probably a good idea anyway as it is the official source.

https://www.iso.org/obp/ui/#iso:pub:PUB500001:en

depending on your script you cold pull AA -ZZ and get all official ISO names/countries and the breakout of countries. like province/state/region etc.

I would ask you to remove the * from the sub area code names

Tanzania
https://www.iso.org/obp/ui/#iso:code:3166:TZ

Subdivision category 3166-2 code Subdivision name Local variant Language code Romanization system Parent subdivision
region TZ-01 Arusha   sw    
region TZ-19 Coast   en    
region TZ-02 Dar es Salaam   sw    
region TZ-03 Dodoma   sw    
region TZ-27* Geita   sw    
region TZ-04 Iringa   sw    
region TZ-05 Kagera   sw    
region TZ-06 Kaskazini Pemba   sw    
region TZ-07 Kaskazini Unguja   sw    
region TZ-28* Katavi   sw    
region TZ-08 Kigoma   sw    
region TZ-09 Kilimanjaro   sw    
region TZ-10 Kusini Pemba   sw    
region TZ-11 Kusini Unguja   sw    
region TZ-12 Lindi   sw    
region TZ-26* Manyara   sw    
region TZ-13 Mara   sw    
region TZ-14 Mbeya   sw    
region TZ-15 Mjini Magharibi   sw    
region TZ-16 Morogoro   sw    
region TZ-17 Mtwara   sw    
region TZ-18 Mwanza   sw    
region TZ-29* Njombe   sw    
region TZ-06 Pemba North   en    
region TZ-10 Pemba South   en    
region TZ-19 Pwani   sw    
region TZ-20 Rukwa   sw    
region TZ-21 Ruvuma   sw    
region TZ-22 Shinyanga   sw    
region TZ-30* Simiyu   sw    
region TZ-23 Singida   sw    
region TZ-31 Songwe   en    
region TZ-31 Songwe   sw    
region TZ-24 Tabora   sw    
region TZ-25 Tanga   sw    
region TZ-07 Zanzibar North   en    
region TZ-11 Zanzibar South   en    
region TZ-15 Zanzibar West   en

viewbox is misspelled

Hello, thanks for the images, I wanted to point out that "viewbox" is misspelled and should be "viewBox" instead in all files, it was causing bugs for me and would be good for future users if you changed it.

Thanks.

Will you take ISO-639-2 ?

Hi, I was curious to know that do you only take contribution (Translation of Country names in various ways) for ISO-632-1 ( having two language code names) only? More clearly can i contribute for the translation of the country names in language with only three ISO codes https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes like Santali language.. As i have seen only 2 iso coded languages contributions in translation.

Combined list with 1 column for each translation (alternative: Add english name to the translated files)

I am looking for a country list that has the name of the country in different languages (e.g. instead of 23 datasets each containing 1 name column, I'd prefer 1 set having 23 name columns (using some standard naming structure - e.g. name where is the iso_alpha2 code for the particular translation).

A different approach could be to simply add the English name as a distinct column in the 22 translated versions of the file. In many use cases there is a need for a local language + English as the international "fall back".

php - use return statement instead of assignment

Hopefully code samples explain all ;)

Current

require '...../world.php'; // $world = [...]

// where the heck the $world variable is coming from? phpstan/psalm/editor complains about undefined variable
print_r($world); 

Proposal

$world = require '...../world.php'; // return [...]

// all is well
print_r($world); 

Add native country name

Could you please add the name of the country in their respective native language? For countries with several languages, use the official, primary or most spoken language.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.