PHPackages                             jrmajor/fluent - 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. jrmajor/fluent

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

jrmajor/fluent
==============

Fluent localization system for PHP

v1.2.0(5mo ago)2716.9k↑141.7%3[4 PRs](https://github.com/jrmajor/fluent-php/pulls)4MITPHPPHP 8.3 - 8.5CI passing

Since May 28Pushed 2mo ago3 watchersCompare

[ Source](https://github.com/jrmajor/fluent-php)[ Packagist](https://packagist.org/packages/jrmajor/fluent)[ Docs](https://github.com/jrmajor/fluent-php)[ GitHub Sponsors](https://github.com/jrmajor)[ RSS](/packages/jrmajor-fluent/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (12)Versions (25)Used By (4)

jrmajor/fluent
==============

[](#jrmajorfluent)

[![Latest Stable Version](https://camo.githubusercontent.com/3dd5c1e24356f5ec0b260139f2145dcf71f3ae08b84a653228c2f591bf382e3b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a726d616a6f722f666c75656e742e737667)](https://packagist.org/packages/jrmajor/fluent)[![Required PHP Version](https://camo.githubusercontent.com/a9e7ffda74cf9d5cfee8cd75b3aec2880a6a340e29ce320dec24424b2680487f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6a726d616a6f722f666c75656e742e737667)](https://packagist.org/packages/jrmajor/fluent)

A PHP implementation of the [Project Fluent](https://projectfluent.org), a localization system designed by Mozilla to unleash the expressive power of the natural language.

Read the [Fluent Syntax Guide](https://projectfluent.org/fluent/guide/) or try it out in the [Fluent Playground](https://projectfluent.org/play/) to learn more about the syntax.

```
shared-photos =
    { $userName } { $photoCount ->
        [one] added a new photo
       *[other] added { $photoCount } new photos
    } to { $userGender ->
        [male] his stream
        [female] her stream
       *[other] their stream
    }.
```

```
$bundle->message('stream.shared-photos', [
    'userName' => 'jrmajor',
    'photoCount' => 2,
    'userGender' => 'male',
]); // jrmajor added 2 new photos to his stream.
```

You may install this package via Composer: `composer require jrmajor/fluent`.

Use [jrmajor/laravel-fluent](https://github.com/jrmajor/laravel-fluent) to integrate Fluent translations into your Laravel application.

Usage
-----

[](#usage)

### Parsing

[](#parsing)

```
use Major\Fluent\Parser\FluentParser;

$parser = new FluentParser(strict: true);

$resource = $parser->parse('hello-user = Hello, { $userName }!');
```

`$strict` constructor argument defaults to `false`. In strict mode syntax errors result in a `ParserException`. Otherwise, they are ignored and represented in AST by `Junk`.

### Message formatting

[](#message-formatting)

```
use Major\Fluent\Bundle\FluentBundle;

$bundle = new FluentBundle('en', strict: true);

$bundle->addResource($resource);
// or
$bundle->addFtl('hello-user = Hello, { $userName }!');

$bundle->message('hello-user', userName: 'World'); // Hello, World!
```

`FluentBundle` is single-language store of translation resources. Its constructor accepts following arguments:

- `string $locale`: Locale to instantiate locale-specific formatters (e.g. en-US, pl, zh-Hant-TW, fr-CA).
- `bool $strict = false`: See [handling errors](#handling-errors).
- `bool $useIsolating = true`: Specifying whether to use Unicode isolation marks (FSI, PDI) for bidirectional interpolations.
- `bool $allowOverrides = false`: Allow overriding existing messages and terms.

#### Adding resources

[](#adding-resources)

Translations can be added to bundle using `addResource()` or `addFtl()` methods. The first one accepts `FluentResource` object returned by the parser, while the second one accepts a raw FTL string.

```
addResource(FluentResource $resource, bool $allowOverrides = null): static

addFtl(string $ftl, bool $allowOverrides = null): static
```

If `$allowOverrides` is `null`, bundle default will be used.

If bundle is in strict mode, `$ftl` parsing will be also done in strict mode.

#### Formatting messages

[](#formatting-messages)

```
message(string $_message, mixed ...$arguments): ?string
```

`message()` method accepts an id of a message as a first parameter and message arguments as named parameters. It returns `null` for missing messages.

```
welcome = Welcome
    .guest = Welcome, Guest
    .user = Welcome, { $userName }
```

```
$bundle->message('welcome'); // Welcome

$bundle->message('goodbye'); // null
```

For attributes, you may use “dot” notation:

```
$bundle->message('welcome.guest'); // Welcome, Guest
```

Message arguments may be passed as named arguments or as an associative array:

```
$bundle->message('welcome.user', userName: 'John'); // Welcome, John
// equivalent to
$bundle->message('welcome.user', ['userName' => 'John']); // Welcome, John
```

#### Handling errors

[](#handling-errors)

By default, all resolver exceptions are ignored and can be obtained using `popErrors()` method. It returns an array of exceptions and clears exception cache, which means the next time you call it, it will return only new errors.

```
$bundle->message('welcome.user'); // Welcome, {$userName}

$errors = $bundle->popErrors();

count($errors);           // 1
$errors[0]->getMessage(); // Unknown variable: $userName.
```

All resolver exceptions extend `ResolverException`. In strict mode they would be thrown right away in `message()` call.

Testing
-------

[](#testing)

```
vendor/bin/phpunit           # Tests
vendor/bin/phpstan analyze   # Static analysis
vendor/bin/php-cs-fixer fix  # Formatting
```

###  Health Score

58

—

FairBetter than 98% of packages

Maintenance79

Regular maintenance activity

Popularity37

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity79

Established project with proven stability

 Bus Factor1

Top contributor holds 95.3% 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 ~110 days

Recently: every ~95 days

Total

16

Last Release

159d ago

Major Versions

v0.4.2 → v1.0.02023-07-09

PHP version history (7 changes)v0.1.0PHP ^8.0

v0.4.0PHP ~8.0.0 || ~8.1.0

v0.4.2PHP 8.1 - 8.2

v1.0.1PHP 8.1 - 8.3

v1.1.0PHP 8.2 - 8.4

v1.1.1PHP 8.3 - 8.4

v1.2.0PHP 8.3 - 8.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/9a821db490b1337a762f89c118ef7952e54c5f4cc473f915b5165f281956a9e3?d=identicon)[jrmajor](/maintainers/jrmajor)

---

Top Contributors

[![jrmajor](https://avatars.githubusercontent.com/u/26096713?v=4)](https://github.com/jrmajor "jrmajor (526 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (17 commits)")[![hakastein](https://avatars.githubusercontent.com/u/13272188?v=4)](https://github.com/hakastein "hakastein (7 commits)")[![wolandtel](https://avatars.githubusercontent.com/u/1917417?v=4)](https://github.com/wolandtel "wolandtel (2 commits)")

---

Tags

localizationinternationalizationi18nlanguagel10npluralparsertranslationasttranslatorlocalegendermozillaftl

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/jrmajor-fluent/health.svg)

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

###  Alternatives

[jrmajor/laravel-fluent

Fluent translations for Laravel

208.4k](/packages/jrmajor-laravel-fluent)[gettext/languages

gettext languages with plural rules

7530.3M11](/packages/gettext-languages)[aplus/language

Aplus Framework Language Library

2351.7M15](/packages/aplus-language)[tractorcow/silverstripe-fluent

Simple localisation for Silverstripe

92421.6k26](/packages/tractorcow-silverstripe-fluent)[delight-im/i18n

Internationalization and localization for PHP

625.2k3](/packages/delight-im-i18n)[inpsyde/multilingual-press

Simply THE multisite-based free open source plugin for your multilingual websites.

2414.0k1](/packages/inpsyde-multilingual-press)

PHPackages © 2026

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