tonglil/localize
Composer 安装命令:
composer require tonglil/localize
包简介
A library to localize location-based attributes and coerce values into desired formats based on regular expressions.
README 文档
README
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
tonglil/localize 适用场景与选型建议
tonglil/localize 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 783 次下载、GitHub Stars 达 0, 最近一次更新时间为 2014 年 10 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「parsing」 「formatting」 「filtering」 「localize」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tonglil/localize 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tonglil/localize 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tonglil/localize 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A library that can render international postal addresses in different formats.
A port of the PEAR Net_HL7 library to PHP5.3+
A data transforming/formatting package for php.
An MT940 bank statement parser for PHP
Run all code formatting tools with one command: pretty
Eloquent file size calculations and formatting for Laravel
统计信息
- 总下载量: 783
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-10-13