tonglil/localize 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tonglil/localize

最新稳定版本:v1.0

Composer 安装命令:

composer require tonglil/localize

包简介

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

README 文档

README

Build Status Coverage Status Scrutinizer Code Quality

Total Downloads Latest Stable Version Latest Unstable Version License

SensioLabsInsight

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

Install

The recommended way to install is through Composer.

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

Country codes are based on ISO 3166-1. Phone numbers can be formatted to E.164 formatting

Locales currently supported:

  • CA

Planned locales:

  • US
  • FR
  • GB
  • AU
  • CN

Locales are stored in src/locales directory.

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

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

统计信息

  • 总下载量: 781
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-10-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固