2017 © Pedro Peláez
 

library localize

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

image

tonglil/localize

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

  • Tuesday, December 23, 2014
  • by tonglil
  • Repository
  • 1 Watchers
  • 0 Stars
  • 590 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Localize

Build Status Coverage Status Scrutinizer Code Quality, (*1)

Total Downloads Latest Stable Version Latest Unstable Version License, (*2)

SensioLabsInsight, (*3)

A library to localize location-based attributes and coerce values into desired formats based on regular expressions., (*4)

Note: this is not a translation or i18n library., (*5)

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

Contents

Install

The recommended way to install is through Composer., (*7)

Update your project's composer.json file to include Localize:, (*8)

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

Then update the project dependencies to include this library:, (*9)

composer update tonglil/localize

After installing, you need to require Composer's autoloader:, (*10)

require 'vendor/autoload.php';

Locales

Country codes are based on ISO 3166-1. Phone numbers can be formatted to E.164 formatting, (*11)

Locales currently supported: - CA, (*12)

Planned locales: - US - FR - GB - AU - CN, (*13)

Locales are stored in src/locales directory., (*14)

Formats

The default formats currently supported:, (*15)

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

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

The Versions

23/12 2014

dev-master

9999999-dev https://github.com/tonglil/Localize

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

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

filtering localization standard formatting regex parsing localize regular expression

18/12 2014

dev-locale-us

dev-locale-us https://github.com/tonglil/Localize

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

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

filtering localization standard formatting regex parsing localize regular expression

18/12 2014

dev-phone-number

dev-phone-number https://github.com/tonglil/Localize

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

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

filtering localization standard formatting regex parsing localize regular expression

11/12 2014

v1.0

1.0.0.0 https://github.com/tonglil/Localize

A library to localize location-based attributes based on regular expressions.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

filtering formatting parsing localize