PHPackages                             tonglil/localize - 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. tonglil/localize

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

tonglil/localize
================

A library to localize location-based attributes and coerce values into desired formats based on regular expressions.

v1.0(11y ago)0781[1 issues](https://github.com/tonglil/Localize/issues)MITPHPPHP &gt;=5.3.0

Since Dec 11Pushed 11y ago1 watchersCompare

[ Source](https://github.com/tonglil/Localize)[ Packagist](https://packagist.org/packages/tonglil/localize)[ Docs](https://github.com/tonglil/Localize)[ RSS](/packages/tonglil-localize/feed)WikiDiscussions master Synced 2d ago

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

Localize
========

[](#localize)

[![Build Status](https://camo.githubusercontent.com/57de2dd40d4507b729b25142516e5308bd802623d9f502ffa996010a9f5d701f/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f746f6e676c696c2f4c6f63616c697a652e737667)](https://travis-ci.org/tonglil/Localize)[![Coverage Status](https://camo.githubusercontent.com/0eac01a4997167b17ea4e5ec9d09c57e074070b5e6aae6f9581df347205422fa/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f746f6e676c696c2f4c6f63616c697a652e737667)](https://coveralls.io/r/tonglil/Localize)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/0424c870e080bc7d78ae3a84f2c1cbce2650ce9cb24b3cc2ea2ac9488358ed4c/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f746f6e676c696c2f4c6f63616c697a652e737667)](https://scrutinizer-ci.com/g/tonglil/Localize/?branch=master)

[![Total Downloads](https://camo.githubusercontent.com/a26de6e5de6c23c85f1717c01d80f22d1dd0e572e35b7d293a8d0fe8b33b2d6a/68747470733a2f2f706f7365722e707567782e6f72672f746f6e676c696c2f6c6f63616c697a652f646f776e6c6f6164732e737667)](https://packagist.org/packages/tonglil/Localize)[![Latest Stable Version](https://camo.githubusercontent.com/188e89fb9880fdc4377ddac58fb508a58e9784369943659eb1bd634778ca64e3/68747470733a2f2f706f7365722e707567782e6f72672f746f6e676c696c2f6c6f63616c697a652f762f737461626c652e737667)](https://packagist.org/packages/tonglil/Localize)[![Latest Unstable Version](https://camo.githubusercontent.com/9b7ca11145e2574bb5b0c8edab880a594a6f256dee681a7ce44e861de309fa88/68747470733a2f2f706f7365722e707567782e6f72672f746f6e676c696c2f6c6f63616c697a652f762f756e737461626c652e737667)](https://packagist.org/packages/tonglil/Localize)[![License](https://camo.githubusercontent.com/8505550f204ff30add906bc0c75d3fd2c4b0494c80b91c9e7ecc68e99b474417/68747470733a2f2f706f7365722e707567782e6f72672f746f6e676c696c2f6c6f63616c697a652f6c6963656e73652e737667)](https://packagist.org/packages/tonglil/Localize)

[![SensioLabsInsight](https://camo.githubusercontent.com/8464fadf6e34394d7cbe36d7c549eead7281007114104bbb89c2614ed1419f1f/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f33616237336237622d353135392d346266652d386338352d3261313564303366393537392f6269672e706e67)](https://insight.sensiolabs.com/projects/3ab73b7b-5159-4bfe-8c85-2a15d03f9579)

A library to localize location-based attributes and coerce values into desired formats based on regular expressions.

Note: *this is not a translation or i18n library.*

More locales to come - please feel free to submit a PR if you would like to help fill the missing holes!

Contents
--------

[](#contents)

- [Installation](#install)
- [Locales](#locales)
- [Formats](#formats)
- [Examples](#examples)
- [API documentation](http://tonglil.github.io/Localize/).

Install
-------

[](#install)

The recommended way to install is through [Composer](http://getcomposer.org).

Update your project's composer.json file to include Localize:

```
{
    "require": {
        "tonglil/localize": "1.*"
    }
}
```

Then update the project dependencies to include this library:

```
composer update tonglil/localize
```

After installing, you need to require Composer's autoloader:

```
require 'vendor/autoload.php';
```

Locales
-------

[](#locales)

Country codes are based on [ISO 3166-1](http://en.wikipedia.org/wiki/ISO_3166-1). Phone numbers can be formatted to [E.164 formatting](http://en.wikipedia.org/wiki/E.164)

Locales currently supported:

- CA

Planned locales:

- US
- FR
- GB
- AU
- CN

Locales are stored in [src/locales](src/locales) directory.

Formats
-------

[](#formats)

The default formats currently supported:

- Region (province/state)
- Post code (postal/zip code)
- Country name
- Phone number (regional "de-facto" formatting or E.164 formatting)

Examples
--------

[](#examples)

```
use Localize\Localize;

// Create a new localize instance.
$localize = new Localize();
// Set the locale using a two digit ISO country code.
$localize->setLocale('CA');

$address = [
    'address'       => '525 Seymour Street',
    'city'          => 'Vancouver',
    'region'        => $localize->region('british columbia', true),
    'postal_code'   => $localize->postalCode('v6b3h7'),
    'country'       => $localize->country('CANADA', false),
    'phone'         => $localize->phone('5555555555'),
];

echo $address['region'];        // BC
echo $address['postal_code'];   // V6B 3H7
echo $address['country'];       // Canada
echo $address['phone'];         // 555-555-5555

// Region and country both accept a second parameter that formats the value to
// its short version when true, otherwise uses the long version by default.
echo $localize->region('ontario', true);    // ON
echo $localize->region('ontario', false);   // Ontario

// Postal code and phone number will attempt to massage a limit amount of
// formatting into the standard output.
echo $localize->phone('555 555-5555');                  // 555-555-5555 regional "de-facto" formatting
echo $localize->phoneE164('+1 555 555-5555');           // 011-1-555-555-5555 full E.164 formatting
echo $localize->phoneE164('+1 555 555-5555', false);    // +1-555-555-5555 common E.164 formatting
echo $localize->postalCode('V6b 3h7');                  // V6B 3H7

// Basic validation is performed; if a match is not found and can not be
// massaged to a format, null is returned.
var_dump($localize->phone('abc-def-gehi')); // null
```

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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

Unknown

Total

1

Last Release

4168d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/11966c19a7e0836010f22fff667040c7f7e371a4bfb6050c3fd5ad395171351d?d=identicon)[tonglil](/maintainers/tonglil)

---

Top Contributors

[![tonglil](https://avatars.githubusercontent.com/u/3250776?v=4)](https://github.com/tonglil "tonglil (28 commits)")

---

Tags

formatterlocalizationphpparsingformattingfilteringlocalize

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tonglil-localize/health.svg)

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

###  Alternatives

[symfony/translation

Provides tools to internationalize your application

6.6k836.5M2.1k](/packages/symfony-translation)[illuminate/translation

The Illuminate Translation package.

6936.4M495](/packages/illuminate-translation)[benconstable/laravel-localize-middleware

Configurable localization middleware for your Laravel &gt;=5.1 application

9231.4k](/packages/benconstable-laravel-localize-middleware)[skillshare/formatphp

Internationalize PHP apps. This library provides an API to format dates, numbers, and strings, including pluralization and handling translations.

8029.6k](/packages/skillshare-formatphp)

PHPackages © 2026

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