PHPackages                             salarmehr/cosmopolitan - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Localization &amp; i18n](/categories/localization)
4. /
5. salarmehr/cosmopolitan

ActiveInternationalisation[Localization &amp; i18n](/categories/localization)

salarmehr/cosmopolitan
======================

Super efficient application localisation

v3.0.0(2w ago)4811.2k↑103.3%6MITPHPPHP &gt;=8.4CI passing

Since Jan 12Pushed 2w ago4 watchersCompare

[ Source](https://github.com/salarmehr/cosmopolitan)[ Packagist](https://packagist.org/packages/salarmehr/cosmopolitan)[ Docs](https://cosmo.miloun.com/?lang=php)[ RSS](/packages/salarmehr-cosmopolitan/feed)WikiDiscussions main Synced yesterday

READMEChangelog (10)Dependencies (3)Versions (17)Used By (0)

Cosmo
=====

[](#cosmo)

Turn raw values — numbers, amounts, dates, codes — into the polished text your users actually read. Effortlessly: no formatting code to write, no duplication to maintain.

Your app stores machine values — a number, a timestamp, a country code. Your users want to read them the way their part of the world writes them. Cosmo does that conversion in a single call, so you stop scattering ad-hoc formatting logic across your codebase and delete the near-duplicate code that collects around it. It's dead simple, production-ready, and fast.

You don't need a multi-language app to benefit — point Cosmo at a single region and everything just comes out right. The same one line already scales to every language, script, calendar and time zone if you ever grow, with no data to ship or maintain.

```
  ┌─ iphone.json ───────────────────┐     ┌─ locale ──────────────────┐
  │ {                               │     │                           │
  │   "model":    "iPhone 17 Pro",  │     │   en_US · en_GB · pt_BR   │
  │   "price":    999,              │     │   zh_CN · ar_SA · hi_IN   │
  │   "speed":    2000,             │     │                           │
  │   "pixels":   1234567,          │     └─────────────┬─────────────┘
  │   "cameras":  3,                │                   │
  │   "released": "2025-09-19"      │                   │
  │ }                               │                   │
  └────────────────┬────────────────┘                   │
                   └─────────────────┬──────────────────┘
                                     ▼
                               ┌───────────┐
                               │   Cosmo   │
                               └─────┬─────┘
                                     ▼
   🇺🇸  United States   ─►  September 19, 2025 · $999.00 · 2,000 MB/s · 1,234,567 · 3 cameras
   🇬🇧  United Kingdom  ─►  19 September 2025 · £999.00 · 2,000 MB/s · 1,234,567 · 3 cameras
   🇧🇷  Brazil          ─►  19 de setembro de 2025 · R$ 999,00 · 2.000 MB/s · 1.234.567 · 3 câmeras
   🇨🇳  China           ─►  2025年9月19日 · ¥999.00 · 2,000 MB/秒 · 1,234,567 · 3 个摄像头
   🇸🇦  Saudi Arabia    ─►  ٢٧ ربيع الأول ١٤٤٧ هـ · ٩٩٩٫٠٠ ر.س. · ٢٬٠٠٠ م.ب/ث · ١٬٢٣٤٬٥٦٧ · ٣ كاميرات
   🇮🇳  India           ─►  19 सितंबर 2025 · ₹999.00 · 2,000 MB/से॰ · 12,34,567 · 3 कैमरे

```

You pass a locale code; Cosmo decides the rest. There's no currency in the data, yet each region gets its own (`$` / `£` / `R$` / `¥` / `ر.س` / `₹`). The thousands separator follows local habit — even India's `12,34,567` grouping — Saudi Arabia switches to the Hijri calendar and right-to-left Arabic-Indic digits, and the camera count takes the correct plural form. All automatically.

Cosmo is implemented consistently across five languages — the same concepts, method names and behaviour: [JavaScript](https://github.com/cosmo-intl/cosmo-js) ([docs](https://cosmo.miloun.com/?lang=js)) · [Python](https://github.com/cosmo-intl/cosmo-python) ([docs](https://cosmo.miloun.com/?lang=python)) · [Java](https://github.com/cosmo-intl/cosmo-java) ([docs](https://cosmo.miloun.com/?lang=java)) · [.NET / C#](https://github.com/cosmo-intl/cosmo-csharp) · **PHP**.

📖 **Full documentation, API reference and live playground:**

Requirements
------------

[](#requirements)

- PHP 8.4+ with the `intl` extension (`php -m | grep intl`)

Install
-------

[](#install)

```
composer require salarmehr/cosmopolitan
```

Quick start
-----------

[](#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"
```

Cosmo is built around the **locale** — a short language-and-region tag like `en_US`, `de_DE` or `fa_IR` that picks all of these conventions at once. Everything it produces is **locale-aware** and read straight from ICU/[CLDR](https://cldr.unicode.org/), so coverage is complete and always current — no locale tables of your own to bundle or keep up to date. Underscore locales (`en_AU`) and [BCP-47](https://www.rfc-editor.org/info/bcp47)[Unicode extensions](https://unicode.org/reports/tr35/#u_Extension)(`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
------------

[](#what-you-get)

- **Locale display names** — languages, regions, scripts, calendars and currencies, plus emoji flags and writing direction.
- **Numbers &amp; money** — decimals, percentages, currencies (inferred from the region), units, compact notation, scientific, ranges, plus spelled-out and ordinal text.
- **Dates &amp; 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](https://unicode-org.github.io/icu/userguide/format_parse/messages/) (`plural`, `selectordinal`, `select`).
- **Parsing &amp; 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](https://cosmo.miloun.com/api-reference/?lang=php) for every method, the [platform notes](https://cosmo.miloun.com/platform-notes/) for `ext-intl`'s binding limits, and [resources](https://cosmo.miloun.com/resources/) for ICU/CLDR references.

Development
-----------

[](#development)

```
composer install
vendor/bin/phpunit
```

Errors
------

[](#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
-------

[](#license)

MIT © Aiden Adrian

###  Health Score

62

—

FairBetter than 99% of packages

Maintenance96

Actively maintained with recent releases

Popularity37

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity83

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 94.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~180 days

Recently: every ~285 days

Total

14

Last Release

18d ago

Major Versions

v0.4 → v1.0.12020-09-15

v1.3 → v2.02026-05-10

v2.0 → v3.0.02026-06-15

PHP version history (4 changes)v0.1PHP &gt;=7.2.0

v1.0.1PHP &gt;=7.2

v1.2PHP &gt;=8.0

v2.0PHP &gt;=8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/d7e3170f70349e934d4bbea0f5ac07d45357dc6e44c3c3d117953fb1c65eccd1?d=identicon)[salarmehr](/maintainers/salarmehr)

---

Top Contributors

[![salarmehr](https://avatars.githubusercontent.com/u/2582036?v=4)](https://github.com/salarmehr "salarmehr (36 commits)")[![alex-bacart](https://avatars.githubusercontent.com/u/13940752?v=4)](https://github.com/alex-bacart "alex-bacart (1 commits)")[![tommygnr](https://avatars.githubusercontent.com/u/929392?v=4)](https://github.com/tommygnr "tommygnr (1 commits)")

---

Tags

internationalisationinternationalizationintllocalisationlocalization

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/salarmehr-cosmopolitan/health.svg)

```
[![Health](https://phpackages.com/badges/salarmehr-cosmopolitan/health.svg)](https://phpackages.com/packages/salarmehr-cosmopolitan)
```

###  Alternatives

[smmoosavi/php-gettext

Wrapper for php-gettext by danilo segan. This library provides PHP functions to read MO files even when gettext is not compiled in or when appropriate locale is not present on the system.

1927.0k1](/packages/smmoosavi-php-gettext)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
