salarmehr/cosmopolitan
Composer 安装命令:
composer require salarmehr/cosmopolitan
包简介
Super efficient application localisation
README 文档
README
Ergonomic application localisation for PHP, powered by the intl extension (ICU).
Cosmo is a thin, ergonomic layer over PHP's bundled ICU, reached through the
intl extension. Give it a locale
(and optionally a time zone) and it formats numbers, money, dates, units, lists and
messages exactly the way your users expect. There is no bundled locale data —
every result comes straight from ICU and CLDR, covering
all languages, scripts, calendars and time zones.
Cosmo is implemented consistently across four languages — the same concepts, method names and behaviour, each built directly on its platform's ICU: JavaScript (docs) · Python (docs) · Java (docs) · PHP.
📖 Full documentation, API reference and live playground: https://cosmo.miloun.com/?lang=php
Requirements
- PHP 8.4+ with the
intlextension (php -m | grep intl)
Install
composer require salarmehr/cosmopolitan
Quick start
use Miloun\Cosmo\Cosmo; new Cosmo('es_ES')->money(11000.4, 'EUR'); // "11.000,40 €" new Cosmo('tr')->unit('temperature', 'celsius', 26, 'short'); // "26°C" new Cosmo('en')->percentage(0.2); // "20%" new Cosmo('fa')->language('en'); // "انگلیسی" // or the helper function (not autoloaded — include src/helper.php or add it // to the "files" array in your composer.json) cosmo('en_AU')->country(); // "Australia"
Underscore locales (en_AU) and BCP-47
Unicode extensions
(fa-IR-u-nu-latn-ca-buddhist) are both accepted. PHP 8.4 lets you call a method
directly on new Cosmo(...) without wrapping parentheses.
What you get
- Locale display names — languages, regions, scripts, calendars and currencies, plus emoji flags and writing direction.
- Numbers & money — decimals, percentages, currencies (inferred from the region), units, compact notation, scientific, ranges, plus spelled-out and ordinal text.
- Dates & times — locale formats in any calendar (Gregorian, Persian, Buddhist…), custom ICU patterns, durations, date ranges, and relative times.
- Text — locale-aware sort and search, word/sentence/grapheme segmentation, case mapping, transliteration and quotation marks.
- Lists —
"A, B, and C"conjunctions and disjunctions. - Messages — ICU MessageFormat (
plural,selectordinal,select). - Parsing & transforms — the inverse formatters for numbers, money and dates, transliteration, UTS #39 spoof checks, and locale tag expansion.
- Raw ICU access — resource-bundle lookups for data the high-level methods don't cover.
See the full API reference for every method,
the platform notes for ext-intl's binding
limits, and resources for ICU/CLDR references.
Development
composer install vendor/bin/phpunit
Errors
Recoverable problems throw Cosmo\CosmoException (extends \Exception), with
InvalidArgumentException and UnsupportedException subclasses — an invalid currency
in strict mode, an unsupported unit, an unknown symbol name, an unformattable date, and
the like.
License
MIT © Aiden Adrian
salarmehr/cosmopolitan 适用场景与选型建议
salarmehr/cosmopolitan 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11.1k 次下载、GitHub Stars 达 47, 最近一次更新时间为 2020 年 01 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 salarmehr/cosmopolitan 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 salarmehr/cosmopolitan 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 11.1k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 47
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-01-12