PHPackages                             petercoles/multilingual-country-list - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. petercoles/multilingual-country-list

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

petercoles/multilingual-country-list
====================================

Lookup Objects for ISO 3166 Country Names and Codes

1.2.13(1y ago)149374.6k↓10.7%34[1 PRs](https://github.com/petercoles/Multilingual-Country-List/pulls)4MITPHPPHP &gt;=7.4CI passing

Since Apr 23Pushed 1y ago2 watchersCompare

[ Source](https://github.com/petercoles/Multilingual-Country-List)[ Packagist](https://packagist.org/packages/petercoles/multilingual-country-list)[ Docs](https://github.com/petercoles/multilingualcountry-list)[ RSS](/packages/petercoles-multilingual-country-list/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (17)Used By (4)

Multilingual Country Lists for Laravel
======================================

[](#multilingual-country-lists-for-laravel)

[![Code Coverage](https://camo.githubusercontent.com/e521effd6ab53f6481a05dc436ca7194d52c5bc1a034715bb62076b014e1b972/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7065746572636f6c65732f4d756c74696c696e6775616c2d436f756e7472792d4c6973742f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/petercoles/Multilingual-Country-List/?branch=master)[![Build Status](https://camo.githubusercontent.com/576ac57ad0f3cf7440772311d1a9aa6a0425bb33e2a049c80bc37ddb36d5259b/68747470733a2f2f7472617669732d63692e6f72672f7065746572636f6c65732f4d756c74696c696e6775616c2d436f756e7472792d4c6973742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/petercoles/Multilingual-Country-List)[![License](https://camo.githubusercontent.com/e498eead712d82d9ee1af0a4850acd2e46ea48c48fb9ce5a3d2ab64f28f95b34/687474703a2f2f696d672e736869656c64732e696f2f3a6c6963656e73652d6d69742d626c75652e737667)](http://doge.mit-license.org)

Introduction
------------

[](#introduction)

I've lost count of the number of times that I've carefully edited a list of 250 of so countries to create the data needed for a select field on a form - and that's just for one language. This thin Laravel wrapper around an industry-maintained list of country names in many, many languages, consigns that tedious task and ongoing maintenance of those lists to the trash bin of history.

The package provides easy access, through a simple API, to country names in an enormously large number of language and locale settings, together with their ISO-3166 alpha-2 two-letter country codes.

Data can be returned as a lookup array or an array of key-value pairs, where both the key and value labels can be set according to the needs of the software consuming them.

Installation
------------

[](#installation)

At the command line run

```
composer require petercoles/multilingual-country-list
```

If you're using Laravel 5.5 or later (and haven't disabled package discovery), you're done. Move on to the usage section below.

If you're using an older version of Laravel, then add the service provider to the providers entry in your config/app.php file

```
    'providers' => [
        // ...
        PeterColes\Countries\CountriesServiceProvider::class,
        // ...
    ],
```

An optional facade is also available and can be enabled by adding the following to the aliases array in your config/app.php file.

```
'Countries' => PeterColes\Countries\CountriesFacade::class,
```

Usage
-----

[](#usage)

Once installed the package exposes two API methods: lookup() and keyValue(), each of which returns a list of countries ordered by the country name in the language being used.

### Lookup

[](#lookup)

The `lookup` method takes two optional parameters: $locale (default 'en') and $flip (default false) and returns a collection. This collection will be cast to a json object by Laravel if returned as a response, or can be cast to an array if needed with the toArray() method.

Locales can be expressed as a language code, e.g. 'fr', or a full locale code, e.g. zh\_CN.

#### Lookup Examples

[](#lookup-examples)

The default is English.

```
Countries::lookup();

// returns

{
  "AF": "Afghanistan",
  ...
  "ZW": "Zimbabwe"
}
```

The flip parameter facilitates reverse lookups, e.g. for typahead components that recognize values, but don't support keys, requiring the key to obtained later.

```
Countries::lookup('es', true);

// returns

{
  "Afganistán": "AF",
  ...
  "Zimbabue": "ZW"
}
```

Non-latin character sets are supported too, including locale settings

```
Countries::lookup('zh_CN');

// returns

{
  "AL": "阿尔巴尼亚",
  ...
  "HK": "中国香港特别行政区"
}
```

### keyValue

[](#keyvalue)

The `keyValue` method takes three optional parameters: $locale (default 'en'), $key (default 'key') and $value (default 'value').

#### Key Value Examples

[](#key-value-examples)

The default is still English.

```
Countries::keyValue();

// returns

[
  {"key": "AF", "value": "Afghanistan"},
  ...
  {"key": "ZW", "value": "Zimbabwe"}
]
```

If you need a key-value list with custom indices, then the $key and $value parameters can be used to redfine them. this might be the case, for example, if you're using a javascript component to generate a select field and that component has expectations as to the indices used in the data that it receoves.

```
Countries::keyValue('zh', 'label', 'text');

// returns

[
  {"label": "AL", "text": "阿尔巴尼亚"},
  ...
  {"label": "HK", "text": "中国香港特别行政区"}
]
```

### Country Names

[](#country-names)

If you just want to get the name of a country for a particular locale, then passing the $isoCode and $locale (default 'en') to the countryName method will return the requested text.

#### Country Name Example

[](#country-name-example)

```
Countries::countryName('BE', 'fr')

// returns

'Belgique'
```

### Tweaking

[](#tweaking)

So, you've got a list of countries, but it doesn't quite meet your needs. Since the lookup and keyValue methods return Laravel collections, tweaking the results is super easy.

#### Filtering

[](#filtering)

The data from which these lists are drawn includes "Eurozone" and, despite some politicans wishes, that's not really a country. Let's remove it.

```
Countries::lookup()->reject(function($country, $key) {
    return $key == 'EZ';
});
```

There are also some entries that may be considered parts of other countries. Without getting into the politics, let's also remove the Canary Islands (Spain) and Guadeloupe (France).

```
Countries::lookup()->reject(function($country, $key) {
    return in_array($key, [ 'EZ', 'IC', 'GP' ]);
});
```

#### Modifying

[](#modifying)

Also, we know that the international code for the United Kingdom is "GB", but our payment gateway is expecteding "UK". So lets change that.

```
Countries::lookup()->mapWithKeys(function($country, $key) {
    return $key == 'GB' ? [ 'UK' => $country ] : [ $key => $country ];
});
```

#### Adding

[](#adding)

The number of recognized countries is growing, but not always as fast as changes on the ground, so, with no comment on the political rights and wrongs, let's add a new one.

```
Countries::lookup()->put('CT', 'Catalonia')->sort();
```

A few warnings here:

- Do check that the code isn't being already.
- Do remember to sort the list after making the addition.
- Don't forget to keep checking the list so that you can remove your addition if it becomes official.

Issues
------

[](#issues)

This package was developed to meet a specific need and then generalised for wider use. If you have a use case not currently met, or see something that appears to not be working correctly, please raise an issue at the [github repo](https://github.com/petercoles/countries/issues).

Contributions
-------------

[](#contributions)

Contributions are welcome, but will generally need tests. I recommend raising an issue first so that proposed changes or enhancements can be discussed before development starts.

License
-------

[](#license)

This package is licensed under the [MIT license](http://opensource.org/licenses/MIT).

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance45

Moderate activity, may be stable

Popularity53

Moderate usage in the ecosystem

Community25

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 91.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~216 days

Recently: every ~279 days

Total

16

Last Release

433d ago

PHP version history (4 changes)1.0.0PHP &gt;=5.6.0

1.2.5PHP ^7.2

1.2.7PHP &gt;=7.2

1.2.9PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/8c55db253e736e0a0960829d2babfe97f49f8143c48aa6b3d941fc5dd7da4c09?d=identicon)[petercoles](/maintainers/petercoles)

---

Top Contributors

[![petercoles](https://avatars.githubusercontent.com/u/2947594?v=4)](https://github.com/petercoles "petercoles (78 commits)")[![jeffreyvr](https://avatars.githubusercontent.com/u/9550079?v=4)](https://github.com/jeffreyvr "jeffreyvr (2 commits)")[![jyrkidn](https://avatars.githubusercontent.com/u/2447042?v=4)](https://github.com/jyrkidn "jyrkidn (2 commits)")[![gehrisandro](https://avatars.githubusercontent.com/u/25097194?v=4)](https://github.com/gehrisandro "gehrisandro (1 commits)")[![marcbelletre](https://avatars.githubusercontent.com/u/6853334?v=4)](https://github.com/marcbelletre "marcbelletre (1 commits)")[![mohamedsabil83](https://avatars.githubusercontent.com/u/10126040?v=4)](https://github.com/mohamedsabil83 "mohamedsabil83 (1 commits)")

---

Tags

laravelISO 3166country codescountry listscountry lookup

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/petercoles-multilingual-country-list/health.svg)

```
[![Health](https://phpackages.com/badges/petercoles-multilingual-country-list/health.svg)](https://phpackages.com/packages/petercoles-multilingual-country-list)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[interaction-design-foundation/laravel-geoip

Support for multiple Geographical Location services.

17221.0k3](/packages/interaction-design-foundation-laravel-geoip)[nedwors/navigator

A Laravel package to ease defining navigation menus

433.1k](/packages/nedwors-navigator)[xefi/faker-php-laravel

Faker php integration with laravel

1915.1k](/packages/xefi-faker-php-laravel)[dcblogdev/laravel-junie

Install pre-configured guides for Jetbrains Junie

392.5k](/packages/dcblogdev-laravel-junie)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
