PHPackages                             yoeunes/icu-parser - 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. [CLI &amp; Console](/categories/cli)
4. /
5. yoeunes/icu-parser

ActiveLibrary[CLI &amp; Console](/categories/cli)

yoeunes/icu-parser
==================

High-performance ICU MessageFormat parser with lexer, AST, type inference, and CLI tooling.

v0.1.0(4mo ago)10MITPHPPHP &gt;=8.2CI passing

Since Jan 10Pushed 4mo agoCompare

[ Source](https://github.com/yoeunes/icu-parser)[ Packagist](https://packagist.org/packages/yoeunes/icu-parser)[ Docs](https://github.com/yoeunes/icu-parser)[ GitHub Sponsors](https://github.com/yoeunes)[ RSS](/packages/yoeunes-icu-parser/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

 [![ICU Parser](art/banner.svg?v=1)](art/banner.svg?v=1)

 [![Author Badge](https://camo.githubusercontent.com/4a38d2f6b2dc78e84f180f1480fb8515999644208f31ca1fc75037e8812da2ce/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f617574686f722d40796f65756e65732d626c75652e737667)](https://www.linkedin.com/in/younes--ennaji) [![GitHub Release Badge](https://camo.githubusercontent.com/d0d286020da85cbca11bdf3d523bce2e9baa90d139d11034df47369416244c65/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7461672f796f65756e65732f6963752d7061727365722e737667)](https://github.com/yoeunes/icu-parser/releases) [![License Badge](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](https://github.com/yoeunes/icu-parser/blob/main/LICENSE) [![Packagist Downloads Badge](https://camo.githubusercontent.com/d5c48965fe21e94620a7d529f9349d7db285d0f54692aea631e58b61094b9191/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f796f65756e65732f6963752d7061727365722e737667)](https://packagist.org/packages/yoeunes/icu-parser) [![GitHub Stars Badge](https://camo.githubusercontent.com/c49d9471916277b202ec8fa647f55f8a3fc1ecf486347b650a310643c6c9deb8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f796f65756e65732f6963752d7061727365722e737667)](https://github.com/yoeunes/icu-parser) [![Supported PHP Version Badge](https://camo.githubusercontent.com/5ccd8ad4aa14621c50fca08abb1364b476fda1cef21ea1d70e8f08b22c28eafb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f796f65756e65732f6963752d7061727365722e737667)](https://packagist.org/packages/yoeunes/icu-parser)

ICU Parser: Static Analysis, Linter &amp; AST Generator
=======================================================

[](#icu-parser-static-analysis-linter--ast-generator)

ICU Parser is a PHP 8.2+ library that treats ICU MessageFormat strings as code.

Unlike simple wrappers around `MessageFormatter`, ICU Parser implements a **compiler-style pipeline** (Lexer → Parser → AST) and provides **static analysis** for ICU messages.

This architecture allows for advanced tooling:

- **Parsing:** Parse ICU messages into a structured, typed AST.
- **Validation:** Detect common syntax and semantic errors.
- **Type Inference:** Extract parameter types from messages.
- **Linting:** Validate translation catalogs across multiple locales.
- **Analysis:** Syntax highlighting, pretty-formatting, and debugging.

Built for validation, analysis, and robust tooling in i18n workflows.

If you are new to ICU Parser, start with the [Quick Start Guide](docs/QUICK_START.md). If you want a short overview, see [docs/overview.md](docs/overview.md).

Getting started
---------------

[](#getting-started)

```
# Install the library
composer require yoeunes/icu-parser

# Optional: improve locale support
composer require symfony/intl

# Try the CLI
bin/icu lint translations/
```

Requirements: PHP 8.2+ and `ext-intl` (the `MessageFormatter` class).

What ICU Parser provides
------------------------

[](#what-icu-parser-provides)

- 🏗️ **Deep Parsing:** Parse ICU MessageFormat strings into a structured, typed AST.
- 🔍 **Type Inference:** Extract parameter types and their expected formats from messages.
- ✅ **Validation:** Detect syntax errors, missing plural categories, and semantic issues.
- 📊 **Catalog Analysis:** Analyze translation files for consistency and completeness.
- 🎨 **Syntax Highlighting:** Colorize ICU messages for better readability.
- 🔧 **Visitor API:** A flexible API for building custom ICU analysis tools.
- 🛠️ **CLI Tooling:** Lint, audit, debug, and highlight messages from the command line.

Philosophy &amp; Scope
----------------------

[](#philosophy--scope)

ICU Parser is a **static analysis tool**, not a runtime formatter.

### What it does

[](#what-it-does)

- **Parse:** Converts ICU MessageFormat strings into an AST.
- **Validate:** Checks for syntax errors and common semantic issues.
- **Analyze:** Infers types, formats messages, and highlights syntax.
- **Lint:** Scans translation files for errors and inconsistencies.

### What it does NOT do

[](#what-it-does-not-do)

- **Runtime Formatting:** It does not format messages at runtime. Use `MessageFormatter` from `ext-intl` for that.
- **Complete ICU Coverage:** It supports the most common ICU constructs but does not cover every edge case or locale-specific nuance.
- **MessageFormat 2 (MF2):** It targets ICU MessageFormat 1.x only.

### Validation notes

[](#validation-notes)

- **Well-tested behavior:** Parsing, AST structure, error offsets, and syntax validation for the supported ICU syntax.
- **Heuristic:** Semantic validation is conservative and may miss edge cases. Treat it as a helpful tool, not a complete validator.
- **Context matters:** Locale-specific rules (e.g., plural categories) vary. Use `symfony/intl` for better locale support.

How it works
------------

[](#how-it-works)

- `IcuParser::parse()` converts an ICU string into an AST.
- The lexer produces a token stream.
- The parser builds an AST (`MessageNode`).
- Visitors walk the AST to validate, infer types, highlight, or format.

For the full architecture, see [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md).

CLI quick tour
--------------

[](#cli-quick-tour)

```
# Parse and validate a message
bin/icu debug "{count, plural, one {# item} other {# items}}"

# Highlight a message
bin/icu highlight "{name}, you have {count, number} items"

# Lint translation files
bin/icu lint translations/

# Audit translation catalogs
bin/icu audit translations/
```

PHP API at a glance
-------------------

[](#php-api-at-a-glance)

```
use IcuParser\IcuParser;
use IcuParser\Validation\SemanticValidator;
use IcuParser\Highlight\HighlightTheme;
use IcuParser\Type\ParameterType;

$parser = new IcuParser();

// Parse a message into AST
$ast = $parser->parse('Hello {name}, you have {count, plural, one {# item} other {# items}}');

// Infer parameter types
$types = $parser->infer('{count, number} {date, date, short}')->all();
// Returns: ['count' => ParameterType::NUMBER, 'date' => ParameterType::DATETIME]

// Validate semantics
$validator = new SemanticValidator();
$result = $validator->validate($ast, 'Hello {name}', 'en');

if (!$result->isValid()) {
    foreach ($result->getErrors() as $error) {
        echo $error->getMessage() . "\n";
    }
}

// Format for readability
$pretty = $parser->format('{gender, select, male {He} other {They}}');
// Output:
// {gender, select,
//     male {He}
//     other {They}
// }

// Highlight syntax
$highlighted = $parser->highlight('{count, number}', HighlightTheme::ansi());
```

Integrations
------------

[](#integrations)

ICU Parser integrates with common PHP tooling:

- **Symfony bundle**: See [docs/overview.md](docs/overview.md)
- **PHPStan**: PHPStan rule (early/experimental)
- **Twig**: Twig extractor (used by the audit command; requires Twig)
- **GitHub Actions**: Use `bin/icu lint` in your CI pipeline

Documentation
-------------

[](#documentation)

Start here:

- [Quick Start](docs/QUICK_START.md) - Get started in a few minutes
- [Overview](docs/overview.md) - Scope and capabilities
- [Usage Guide](docs/usage.md) - Detailed API usage
- [ICU Support](docs/icu-support.md) - Supported constructs

Key references:

- [Architecture](docs/ARCHITECTURE.md) - Internal design
- [Formatting](docs/formatting.md) - Formatting and highlighting

Contributing
------------

[](#contributing)

Contributions are welcome! See [`CONTRIBUTING.md`](CONTRIBUTING.md) to get started.

```
# Set up development environment
composer install

# Run tests
composer phpunit

# Check code style
composer phpcs

# Run static analysis
composer phpstan

# Run full lint (includes all of the above)
composer lint
```

License
-------

[](#license)

Released under the [MIT License](LICENSE).

Support
-------

[](#support)

If you run into issues or have questions, please open an issue on GitHub: .

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance76

Regular maintenance activity

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

129d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/719ac0f6bf24d689686134530caf539727d784ad4a66c81ad5dcdba161b4ea0a?d=identicon)[yoeunes](/maintainers/yoeunes)

---

Top Contributors

[![yoeunes](https://avatars.githubusercontent.com/u/10859693?v=4)](https://github.com/yoeunes "yoeunes (32 commits)")

---

Tags

phpclii18npluralicuparserlexerastselectmessageformat

### Embed Badge

![Health badge](/badges/yoeunes-icu-parser/health.svg)

```
[![Health](https://phpackages.com/badges/yoeunes-icu-parser/health.svg)](https://phpackages.com/packages/yoeunes-icu-parser)
```

###  Alternatives

[nunomaduro/termwind

It's like Tailwind CSS, but for the console.

2.5k239.8M286](/packages/nunomaduro-termwind)[yoeunes/regex-parser

A powerful PCRE regex parser with lexer, AST builder, validation, ReDoS analysis, and syntax highlighting. Zero dependencies, blazing fast, and production-ready.

2946.4k5](/packages/yoeunes-regex-parser)[nunomaduro/laravel-console-task

Laravel Console Task is a output method for your Laravel/Laravel Zero commands.

2582.1M11](/packages/nunomaduro-laravel-console-task)[alecrabbit/php-cli-snake

Lightweight cli spinner with zero dependencies

29211.3k5](/packages/alecrabbit-php-cli-snake)[jrmajor/fluent

Fluent localization system for PHP

2716.9k5](/packages/jrmajor-fluent)

PHPackages © 2026

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