PHPackages                             chipslays/phrase - 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. chipslays/phrase

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

chipslays/phrase
================

Internationalization library for PHP.

1.0.2(4y ago)01791MITPHP

Since Jun 16Pushed 4y ago1 watchersCompare

[ Source](https://github.com/chipslays/phrase)[ Packagist](https://packagist.org/packages/chipslays/phrase)[ RSS](/packages/chipslays-phrase/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (1)

🌐 Phrase
========

[](#-phrase)

[![GitHub Workflow Status](https://camo.githubusercontent.com/7f8dfd4ff8d734e9fb38b516a9924de4d2ff6a207552f2698dad2f3e1ed9bf7c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f63686970736c6179732f7068726173652f7465737473)](https://camo.githubusercontent.com/7f8dfd4ff8d734e9fb38b516a9924de4d2ff6a207552f2698dad2f3e1ed9bf7c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f63686970736c6179732f7068726173652f7465737473)[![GitHub](https://camo.githubusercontent.com/2449613903ae9a5c58ddd7ed872b156a2a5ac787abfa58985344b3e3a9465498/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f63686970736c6179732f7068726173653f636f6c6f723d253233613639353763)](https://camo.githubusercontent.com/2449613903ae9a5c58ddd7ed872b156a2a5ac787abfa58985344b3e3a9465498/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f63686970736c6179732f7068726173653f636f6c6f723d253233613639353763)

Internationalization library for PHP.

Features
--------

[](#features)

- Translations based on [`JSON`](examples/locales/json), [`YAML`](examples/locales/yaml) files;
- Easy addition of new [sources files](src/Engine);
- Interpolated translations;
- Pluralization;

Installation
------------

[](#installation)

```
composer require chipslays/phrase
```

Setup
-----

[](#setup)

Locale file: `locales/yaml/en_US.yml`

```
# interpolated message
hello: Hello {name}!

# pluralization
plural: I have {count} {{eng:{count},melon}} and {money} {{eng:{money},dollar}}.

# message can be a array
array:
  text: This is my flag.
  image: images/en-flag.jpg
  myKey: myValue
```

Locale file: `locales/json/en_US.json`

```
{
    "hello": "Hello {name}!",
    "plural": "I have {count} {{eng:{count},melon}} and {money} {{eng:{money},dollar}}.",
    "array": {
        "text": "This is my flag.",
        "image": "images/en-flag.jpg"
    }
}
```

Usage
-----

[](#usage)

### Create `Phrase` instance

[](#create-phrase-instance)

```
// Engine constructor
__construct(string $root, string $locale, ?string $fallback);
```

```
use Chipslays\Phrase\Phrase;
use Chipslays\Phrase\Engine\JsonEngine;

$engine = new JsonEngine(__DIR__ . '/locales/json', 'en_US');
$phrase = new Phrase($engine);
$phrase->get(...);
```

```
use Chipslays\Phrase\Phrase;
use Chipslays\Phrase\Engine\YamlEngine;

$engine = new YamlEngine(__DIR__ . '/locales/yaml', 'en_US');
$phrase = new Phrase($engine);
$phrase->get(...);
```

```
use Chipslays\Phrase\Phrase;
use Chipslays\Phrase\Engine\JsonEngine;

$engine = new JsonEngine(__DIR__ . '/locales/json', 'en_US');
Phrase::setEngine($engine);
Phrase::get(...);
```

### Get message

[](#get-message)

```
$phrase->get(string $key, ?array $replace = null, ?string $locale = null);

# key - locale message key
# replace - array with interpolation
# locale - force locale (useful when using multiple locales at the same time)
```

```
$phrase->get('hello');
Phrase::get('hello');
__('hello');
```

Pass language code for force use.

```
$phrase->get('hello', null, 'ru_RU');
Phrase::get('hello', null, 'ru_RU');
__('hello', null, 'ru_RU');
```

### Interpolation

[](#interpolation)

Pass named arguments to interpolate your translations.

```
$phrase->get('hello', ['{name}' => 'John Doe']);
Phrase::get('hello', ['{name}' => 'John Doe']);
__('hello', ['{name}' => 'John Doe']);

// Hello John Doe!
```

### Pluralization

[](#pluralization)

English pluralization phrase:

```
{{eng:{count},melon}}

```

Russian pluralization phrase:

```
{{rus:{count},арбуз,арбуза,арбузов}}

```

```
# english locale file
# for english plural word have 1 form
...
plural: I have {count} {{eng:{count},melon}} and {money} {{eng:{money},dollar}}.
....
```

```
# russian locale file
# for russian plural word have 3 forms
...
plural: У меня есть {count} {{rus:{count},арбуз,арбуза,арбузов}} и {money} {{rus:{money},рубль,рубля,рублей}}
....
```

```
$phrase->get('plural', ['{count}' => 1, '{money}' => 100])
Phrase::get('plural', ['{count}' => 1, '{money}' => 100])
__('plural', ['{count}' => 1, '{money}' => 100])

// I have 1 melon and 100 dollars.
```

### Merge locale messages (`load`, `patch`)

[](#merge-locale-messages-load-patch)

Use `patch` method if you need to add messages to an already loaded file.

If this locale was not previously loaded, it will simply be loaded.

Use `load` method for delete and overwrite all previous messages by locale.

```
use Chipslays\Phrase\Phrase;
use Chipslays\Phrase\Engine\YamlEngine;

$engine = new YamlEngine(__DIR__ . '/locales/yaml', 'en_US');
$phrase = new Phrase($engine);

// this method loaded en_US.yml file from MyPlugin dir and merge with previously loaded locale en_US
$phrase->patch(__DIR__ . '/locales/plugins/MyPlugin/', 'en_US');

// this method delete and overwrite all previous messages
$phrase->load(__DIR__ . '/locales/yaml', 'en_US');
```

```
use Chipslays\Phrase\Plural;

echo Plural::eng(10, 'melon'); // melons
echo Plural::rus(10, ['арбуз', 'арбуза', 'арбузов']); // арбузов
```

### Helpers

[](#helpers)

```
__(string $key, ?array $replace = null, ?string $locale = null): string|array
```

```
__('hello', ['{name}' => 'John Doe'], 'en_US');
```

### Custom locale file (Engine)

[](#custom-locale-file-engine)

Example for `YamlEngine`:

```
use Chipslays\Phrase\Engine\AbstractEngine;
use Chipslays\Phrase\Exceptions\PhraseException;

class YamlEngine extends AbstractEngine
{
    /**
     * @param string $locale
     * @return void
     *
     * @throws PhraseException
     */
    protected function load(string $locale): void
    {
        $path = $this->root . '/' . $locale . '.yml';

        if (!file_exists($path)) {
            throw new PhraseException("Locale file not found in path {$path}", 1);
        }

        $this->locales[$locale] = yaml_parse_file($path);
    }
}
```

License
-------

[](#license)

MIT

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 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

Every ~37 days

Total

3

Last Release

1720d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/19103498?v=4)[chipslays](/maintainers/chipslays)[@chipslays](https://github.com/chipslays)

---

Top Contributors

[![chipslays](https://avatars.githubusercontent.com/u/19103498?v=4)](https://github.com/chipslays "chipslays (18 commits)")

---

Tags

internationalization-librarylightweightlocalizationphptranslation

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/chipslays-phrase/health.svg)

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

###  Alternatives

[symfony/translation

Provides tools to internationalize your application

6.6k836.5M2.1k](/packages/symfony-translation)[nesbot/carbon

An API extension for DateTime that supports 281 different languages.

169661.4M4.8k](/packages/nesbot-carbon)[joedixon/laravel-translation

A tool for managing all of your Laravel translations

717911.4k11](/packages/joedixon-laravel-translation)[illuminate/translation

The Illuminate Translation package.

6936.4M495](/packages/illuminate-translation)[lajax/yii2-translate-manager

Translation management extension for Yii 2

227578.8k13](/packages/lajax-yii2-translate-manager)[larswiegers/laravel-translations-checker

Make sure your laravel translations are checked and are included in all languages.

256423.2k2](/packages/larswiegers-laravel-translations-checker)

PHPackages © 2026

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