cakephp/i18n
Composer 安装命令:
composer require cakephp/i18n
包简介
CakePHP Internationalization library with support for messages translation and dates and numbers localization
关键字:
README 文档
README
CakePHP Internationalization Library
The I18n library provides a I18n service locator that can be used for setting
the current locale, building translation bundles and translating messages.
Additionally, it provides the Time and Number classes which can be used to
output dates, currencies and any numbers in the right format for the specified locale.
Usage
Internally, the I18n class uses Aura.Intl.
Getting familiar with it will help you understand how to build and manipulate translation bundles,
should you wish to create them manually instead of using the conventions this library uses.
Setting the Current Locale
use Cake\I18n\I18n; I18n::setLocale('en_US');
Setting path to folder containing po files.
use Cake\Core\Configure; Configure::write('App.paths.locales', ['/path/with/trailing/slash/']);
Please refer to the CakePHP Manual for details about expected folder structure and file naming.
Translating a Message
echo __( 'Hi {0,string}, your balance on the {1,date} is {2,number,currency}', ['Charles', '2014-01-13 11:12:00', 1354.37] ); // Returns Hi Charles, your balance on the Jan 13, 2014, 11:12 AM is $ 1,354.37
Creating Your Own Translators
use Cake\I18n\I18n; use Cake\I18n\Package; I18n::translator('animals', 'fr_FR', function () { $package = new Package( 'default', // The formatting strategy (ICU) 'default', // The fallback domain ); $package->setMessages([ 'Dog' => 'Chien', 'Cat' => 'Chat', 'Bird' => 'Oiseau' ... ]); return $package; }); I18n::getLocale('fr_FR'); __d('animals', 'Dog'); // Returns "Chien"
Formatting Time
$time = Time::now(); echo $time; // shows '4/20/14, 10:10 PM' for the en-US locale
Formatting Numbers
echo Number::format(100100100);
echo Number::currency(123456.7890, 'EUR'); // outputs €123,456.79
Documentation
Please make sure you check the official I18n documentation.
The documentation for the Time class contains instructions on how to configure and output time strings for selected locales.
The documentation for the Number
class shows how to
use the Number class for displaying numbers in specific locales.
cakephp/i18n 适用场景与选型建议
cakephp/i18n 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 169.8k 次下载、GitHub Stars 达 29, 最近一次更新时间为 2015 年 01 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「i18n」 「translation」 「internationalisation」 「date」 「cakephp」 「number」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 cakephp/i18n 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cakephp/i18n 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 cakephp/i18n 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easy to use i18n translation PHP class for multi-language websites
A custom URL rule class for Yii 2 which allows to create translated URL rules
Arbitrary-precision floating-point maths with locale-aware formatting - integrated with Laravel or stand-alone
A Laravel Eloquent model trait for translatable resource
Internationalized routing with minimal performance cost.
Bureaux A Partager Edit - Parse, validate, manipulate, and display dates in PHP w/ i18n support. Inspired by moment.js
统计信息
- 总下载量: 169.8k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 29
- 点击次数: 35
- 依赖项目数: 23
- 推荐数: 5
其他信息
- 授权协议: MIT
- 更新时间: 2015-01-13