PHPackages                             compositephp/localization - 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. compositephp/localization

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

compositephp/localization
=========================

Easy to use Localization and Pluralization, based on files

v0.1.0(3y ago)29MITPHPPHP ^8.1

Since Oct 24Pushed 3y ago1 watchersCompare

[ Source](https://github.com/compositephp/localization)[ Packagist](https://packagist.org/packages/compositephp/localization)[ RSS](/packages/compositephp-localization/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Composite Localization
======================

[](#composite-localization)

Simple translation and pluralization php library based on files.

Overview:

- [Requirements](#requirements)
- [Installation](#installation)
- [Localization](#localization)
- [Pluralization](#pluralization)

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

[](#requirements)

- PHP 8.1+
- PDO Extension with desired database drivers

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

[](#installation)

Install package via composer:

```
$ composer require compositephp/localization
```

Localization
------------

[](#localization)

First, you need to create new class and extend from `Composite\Localization\AbstractLocalization`

```
use Composite\Localization\AbstractLocalization;
use Composite\Localization\Language;

class Localization extends AbstractLocalization
{
    public function __construct(Language $language)
    {
        parent::__construct(
            language: $language,
            sourcePath: '/directory/to/your/locale/files',
        );
    }

    public function general(string $text, array $placeholders = []): string
    {
        return $this->get('general', $text, $placeholders);
    }

    public function profile(string $text, array $placeholders = []): string
    {
        return $this->get('profile', $text, $placeholders);
    }
    //other categories
    //...
}
```

Usage:

```
```

Second, create category files in your localization source path `/directory/to/your/locale/files`:

```
- general.php
- profile.php

```

Example content of `general.php`

```
use Composite\Localization\Language;

return [
    'Hello World!' => [
        Language::FR->value => 'Bonjour le monde!'
    ],
    'hello_world' => [
        Language::EN->value => 'Hello World!',
        Language::FR->value => 'Bonjour le monde!',
    ],
    'Hello {{first_name}} {{last_name}}!' => [
        Language::FR->value => 'Bonjour {{first_name}} {{last_name}}!',
    ],
    'hello_fullname' => [
        Language::EN->value => 'Hello {{first_name}} {{last_name}}!',
        Language::FR->value => 'Bonjour {{first_name}} {{last_name}}!',
    ],
    'Hello {{name}}, you have {{num}} [[new_comment:num]]' => [
        Language::FR->value => 'Bonjour {{name}}, vous avez {{num}} [[new_comment:num]]',
    ],
];
```

Usage:

```
use Composite\Localization\Language;

$localization = new Localization(Language::FR);

$localization->general('Hello World!'); //Bonjour le monde!

$localization->general('hello_world'); //Bonjour le monde!

$localization->general(
    'Hello {{first_name}} {{last_name}}!',
    ['first_name' => 'John', 'last_name' => 'Smith']
); //Bonjour John Smith!

$localization->general(
    'hello_fullname',
    ['first_name' => 'John', 'last_name' => 'Smith']
); //Bonjour John Smith!

//if translation not exists localization instance will still output it as is

$localization->general('Bye World!'); //Bye World!

$localization->general('bye_world'); //bye_world

$localization->general(
    'Bye {{first_name}} {{last_name}}!',
    ['first_name' => 'John', 'last_name' => 'Smith']
); //Bye John Smith!
```

Pluralization
-------------

[](#pluralization)

Create a file `_plural.php` inside folder with translation categories `/directory/to/your/locale/files`:

```
use Composite\Localization\Language;
use Composite\Localization\Plurals\EnglishPlural;
use Composite\Localization\Plurals\FrenchPlural;

return [
    'new_comment' => [
        Language::EN->value => new EnglishPlural('new comment', 'new comments'),
        Language::FR->value => new FrenchPlural('nouveau commentaire', 'nouveaux commentaires'),
    ],
];
```

Usage:

```
$localization->general(
    'Hello {{name}}, you have {{num}} [[new_comment:num]]',
    ['name' => 'John', 'num' => 1]
); //Bonjour John, vous avez 1 nouveau commentaire

$localization->general(
    'Hello {{name}}, you have {{num}} [[new_comment:num]]',
    ['name' => 'John', 'num' => 2]
); //Bonjour John, vous avez 2 nouveaux commentaires
```

License:
--------

[](#license)

MIT License (MIT). Please see [`LICENSE`](./LICENSE) for more information. Maintained by Composite PHP.

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

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

1301d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/585d414228f543dd8e3eb606f05a4b7bd52388a671abb52b70cc5bad4f7d1739?d=identicon)[compositephp](/maintainers/compositephp)

---

Tags

easy-to-uselocalizationphpphp81pluralizationtranslations

###  Code Quality

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/compositephp-localization/health.svg)

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

###  Alternatives

[jms/translation-bundle

Puts the Symfony Translation Component on steroids

42510.8M63](/packages/jms-translation-bundle)[lunetics/locale-bundle

A Bundle for switching Languages

1861.1M8](/packages/lunetics-locale-bundle)[skillshare/formatphp

Internationalize PHP apps. This library provides an API to format dates, numbers, and strings, including pluralization and handling translations.

8029.6k](/packages/skillshare-formatphp)

PHPackages © 2026

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