PHPackages                             macmotp/locale - 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. [Localization &amp; i18n](/categories/localization)
4. /
5. macmotp/locale

ActiveLibrary[Localization &amp; i18n](/categories/localization)

macmotp/locale
==============

A curated library to handle locale in PHP

v1.0.3(1y ago)507.1k↓26.8%3MITPHPPHP &gt;=8.2

Since Sep 25Pushed 1y ago3 watchersCompare

[ Source](https://github.com/macmotp/locale)[ Packagist](https://packagist.org/packages/macmotp/locale)[ Docs](https://github.com/macmotp/locale)[ RSS](/packages/macmotp-locale/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (4)Versions (11)Used By (0)

A curated library to handle locale in PHP
=========================================

[](#a-curated-library-to-handle-locale-in-php)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b584cbf5cc3ca2c3e655e36627cc4d870bb4f27596b50dc7ebdd7077aea9207b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d61636d6f74702f6c6f63616c652e737667)](https://packagist.org/packages/macmotp/locale)[![Total Downloads](https://camo.githubusercontent.com/05d4f93d1a3e9dd70acf444336a6b805b955beb2888eb32683707806429bce0c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d61636d6f74702f6c6f63616c652e737667)](https://packagist.org/packages/macmotp/locale)

**Simple and light PHP library that handles Countries, Currencies, Languages, and Timezones**

Useful for any application that needs localization.

Requirements
------------

[](#requirements)

- PHP &gt;= 8.2

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

[](#installation)

Install the package via composer:

```
composer require macmotp/locale
```

Usage
-----

[](#usage)

### Create Country objects

[](#create-country-objects)

```
use Macmotp\Country;
use Macmotp\Countries\Support\CountryCode;

// Create the object
$countryCode = CountryCode::US; // Use alpha2 ISO code
$country = new Country($countryCode);

// Alternative methods:
$country = new Country('US');
$country = Country::make($countryCode);

echo $country->toArray();

// [
//    'continent' => 'North America',
//    'name' => 'United States of America',
//    'capital' => 'Washington, D.C.',
//    'code' => 'US',
//    'alpha3_code' => 'USA',
//    'dial_code' => '+1',
//    'tld' => '.us',
//    'date_format' => 'm-d-Y',
//    'flag' => 'us',
//    'default_currency' => [
//       'name' => 'United States Dollar',
//       'code' => 'USD',
//       'symbol' => '$',
//       'flag' => 'us',
//       'format' => [
//          ...
//       ],
//    ],
//    'default_timezone' => [
//       'name' => 'America/New_York',
//       'code' => 'America/New_York',
//    ],
//    'default_language' => [
//       'name' => 'English',
//       'code' => 'en',
//       'english_name' => 'English',
//       'flag' => 'gb',
//    ],
//    'currencies' => [...],
//    'timezones' => [...],
//    'languages' => [...],
// ]
```

### List of basic dynamic methods

[](#list-of-basic-dynamic-methods)

- `getContinent()`: it returns the continent (string);
- `getName()`: it returns the name (string);
- `getCapital()`: it returns the capital (string);
- `getCode()`: it returns the country code (alpha2) (string);
- `getAlpha3Code()`: it returns the country code (alpha3) (string);
- `getDialCode()`: it returns the dial code (string);
- `getTld()`: it returns the internet tld (string);
- `getDateFormat()`: it returns the date format (string);
- `getFlag()`: it returns the flag code (string);
- `getDefaultCurrency()`: it returns the default currency (object `Macmotp\Currency`);
- `getDefaultTimezone()`: it returns the default timezone (object `Macmotp\Timezone`);
- `getDefaultLanguage()`: it returns the default locale language (object `Macmotp\Language`);
- `toArray()`: it returns the object into array;

```
// Example
use Macmotp\Country;

$country = new Country('US');

echo $country->getDefaultCurrency()->getCode();
// (string) 'USD'

echo $country->getFlag();
// (string) 'us'
```

### List of advanced dynamic methods

[](#list-of-advanced-dynamic-methods)

- `getCurrencies()`: it returns a Collection with all the currencies adopted in that country;
- `getTimezones()`: it returns a Collection with all the timezones applied in that country;
- `getLanguages()`: it returns a Collection with all the languages used in that country;

```
// Example
use Macmotp\Country;
use Macmotp\Countries\Support\CountryCode;

$country = new Country(CountryCode::AU);

echo $country->getTimezones();
// (Collection)
// [
//    ['code' => 'Antarctica/Macquarie', 'name' => 'Antarctica/Macquarie'],
//    ['code' => 'Australia/Adelaide', 'name' => 'Australia/Adelaide'],
//    ['code' => 'Australia/Brisbane', 'name' => 'Australia/Brisbane'],
//    ['code' => 'Australia/Broken_Hill', 'name' => 'Australia/Broken_Hill'],
//    ['code' => 'Australia/Darwin', 'name' => 'Australia/Darwin'],
//    ['code' => 'Australia/Eucla', 'name' => 'Australia/Eucla'],
//    ['code' => 'Australia/Hobart', 'name' => 'Australia/Hobart'],
//    ['code' => 'Australia/Lindeman', 'name' => 'Australia/Lindeman'],
//    ['code' => 'Australia/Lord_Howe', 'name' => 'Australia/Lord_Howe'],
//    ['code' => 'Australia/Melbourne', 'name' => 'Australia/Melbourne'],
//    ['code' => 'Australia/Perth', 'name' => 'Australia/Perth'],
//    ['code' => 'Australia/Sydney', 'name' => 'Australia/Sydney'],
//  ]
```

### List of Countries in the package

[](#list-of-countries-in-the-package)

```
use Macmotp\Country;

$list = Country::all();
// it returns a Collection with all countries
```

### Filter Countries by property

[](#filter-countries-by-property)

- `usingCurrency($currencyCode)`: it returns a Collection with all the currencies adopted in that country;
- `usingLanguage($language)`: it returns a Collection with all the countries speaking a specific language;
- `ofContinent($continent)`: it returns a Collection with all the countries that belong to a continent;

```
// Examples
use Macmotp\Continent;
use Macmotp\Country;
use Macmotp\Language;

echo Country::all()->usingCurrency('USD');
// (Collection) [
//    [
//       'continent' => 'North America',
//       'name' => 'United States of America',
//       'code' => 'US',
//       ...
//    ],
//    [
//       'continent' => 'North America',
//       'name' => 'El Salvador',
//       'code' => 'ES',
//       ...
//    ],
//    ...
// ]

$list = Country::all()->usingLanguage(Language::ENGLISH);
// (Collection) [
//    [
//       'continent' => 'North America',
//       'name' => 'United States of America',
//       'code' => 'US',
//       ...
//    ],
//    [
//       'continent' => 'Europe',
//       'name' => 'United Kingdom',
//       'code' => 'GB',
//       ...
//    ],
//    ...
// ]
```

**These methods can be chained, for example: `Country::all()->ofContinent(Continent::EUROPE)->usingLanguage(Language::ENGLISH);`**

Localization
------------

[](#localization)

In addition to the default functions, it's possible to localize the response. By default, English is used as primary locale.

```
use Macmotp\Country;
use Macmotp\Countries\Support\CountryCode;
use Macmotp\Languages\Support\Locale;

// Create the object with locale
$country = new Country(CountryCode::US);

echo $country->setLocale(Locale::JAPANESE)->toArray();

// [
//    'continent' => '北アメリカ',
//    'name' => 'アメリカ合衆国',
//    'capital' => 'ワシントンD.C.',
//    ...
// ]
```

#### Supported Locales

[](#supported-locales)

- `Locale::ARABIC = 'ar'`;
- `Locale::GERMAN = 'de'`;
- `Locale::ENGLISH = 'en'`;
- `Locale::SPANISH = 'es'`;
- `Locale::FRENCH = 'fr'`;
- `Locale::HINDI = 'hi'`;
- `Locale::HUNGARIAN = 'hu'`;
- `Locale::INDONESIAN = 'id'`;
- `Locale::ITALIAN = 'it'`;
- `Locale::JAPANESE = 'ja'`;
- `Locale::KOREAN = 'ko'`;
- `Locale::MALAY = 'ms'`;
- `Locale::DUTCH = 'nl'`;
- `Locale::PORTUGUESE = 'pt'`;
- `Locale::ROMANIAN = 'ro'`;
- `Locale::RUSSIAN = 'ru'`;
- `Locale::TAMIL = 'ta'`;
- `Locale::CHINESE = 'zh'`;

### Flags

[](#flags)

In addition to the source code, you can find a set of SVG flags [here](./src/Assets/Flags). These icons are tight to the `getFlag()` method, and they are associated also with Currencies and Languages.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [changelog](changelog.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [contributing](.github/contributing.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](.github/security.md) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Marco Gava](https://github.com/macmotp)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](license.md) for more information.

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~11 days

Total

5

Last Release

556d ago

Major Versions

v0.1.0 → v1.0.02024-10-03

### Community

Maintainers

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

---

Top Contributors

[![macmotp](https://avatars.githubusercontent.com/u/6443339?v=4)](https://github.com/macmotp "macmotp (9 commits)")

---

Tags

phplocalizationlanguagescountrieslocaletimezonesmacmotp

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/macmotp-locale/health.svg)

```
[![Health](https://phpackages.com/badges/macmotp-locale/health.svg)](https://phpackages.com/packages/macmotp-locale)
```

###  Alternatives

[codezero/laravel-localized-routes

A convenient way to set up, manage and use localized routes in a Laravel app.

543638.1k4](/packages/codezero-laravel-localized-routes)[opgginc/codezero-laravel-localized-routes

A convenient way to set up, manage and use localized routes in a Laravel app.

2770.1k1](/packages/opgginc-codezero-laravel-localized-routes)[awes-io/localization-helper

Package for convenient work with Laravel's localization features

3527.1k4](/packages/awes-io-localization-helper)[pharaonic/laravel-locations

Laravel - Countries\[States/Cities, Currency, Phone Code, Languages, Capital\] &amp; Continents &amp; Timezones.

102.4k1](/packages/pharaonic-laravel-locations)

PHPackages © 2026

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