PHPackages                             mjahn/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. mjahn/multilingual-country-list

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

mjahn/multilingual-country-list
===============================

Lookup Objects for ISO 3166 Country Names and Codes

1.2.5(6y ago)011MITPHPPHP &gt;=5.6.0

Since Apr 23Pushed 6y agoCompare

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

READMEChangelog (1)Dependencies (3)Versions (9)Used By (0)

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

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

[![SensioLabsInsight](https://camo.githubusercontent.com/79ad59d24c0daf6a3b05d27932f9cecef892b2f0cc505b7123cddffe2a273cb5/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f31383239323436372d323534372d343631612d383962632d6330663737613162653238362f6d696e692e706e67)](https://insight.sensiolabs.com/projects/18292467-2547-461a-89bc-c0f77a1be286)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/990fcb52d20ff326389ee04746eef8de36ea90316a1dd3a76e17af8e7cd291aa/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7065746572636f6c65732f4d756c74696c696e6775616c2d436f756e7472792d4c6973742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/petercoles/Multilingual-Country-List/?branch=master)[![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.

#### Examples

[](#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').

#### Examples

[](#examples-1)

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": "中国香港特别行政区"}
]
```

### 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).

License
-------

[](#license)

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

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 95.9% 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 ~176 days

Recently: every ~202 days

Total

8

Last Release

2433d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d63e161bee31c6d7f9e01332e4a7eb87d73a33d22fa994734019fdb6068d0a99?d=identicon)[mjahn](/maintainers/mjahn)

---

Top Contributors

[![petercoles](https://avatars.githubusercontent.com/u/2947594?v=4)](https://github.com/petercoles "petercoles (47 commits)")[![mjahn](https://avatars.githubusercontent.com/u/135339?v=4)](https://github.com/mjahn "mjahn (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/mjahn-multilingual-country-list/health.svg)

```
[![Health](https://phpackages.com/badges/mjahn-multilingual-country-list/health.svg)](https://phpackages.com/packages/mjahn-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)[petercoles/multilingual-country-list

Lookup Objects for ISO 3166 Country Names and Codes

149374.6k4](/packages/petercoles-multilingual-country-list)[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)
