PHPackages                             seworqs/commons-i18n - 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. seworqs/commons-i18n

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

seworqs/commons-i18n
====================

Easy to use translations for your PHP project.

2.1.0(12mo ago)08Apache-2.0PHPPHP ^8.1

Since May 9Pushed 12mo agoCompare

[ Source](https://github.com/seworqs/commons-i18n)[ Packagist](https://packagist.org/packages/seworqs/commons-i18n)[ RSS](/packages/seworqs-commons-i18n/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (4)Used By (0)

Seworqs Commons i18n
====================

[](#seworqs-commons-i18n)

A lightweight, standalone internationalization module for PHP 8.1+ that integrates both PHP‑array and Gettext back‑ends with advanced locale fallback logic and PSR‑11 compatibility. Includes support for translatable enums and global translation helpers.

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

[](#installation)

```
composer require seworqs/commons-i18n
```

Usage
-----

[](#usage)

```
use Seworqs\Commons\I18n\Factory\TranslatorFactory;
use Seworqs\Commons\I18n\Registry\TranslatorRegistry;

$translator = TranslatorFactory::createStandAlone([
    'locale' => 'nl_BE',
    'fallbackLocale' => 'en',
    'translation_file_patterns' => [
        ['type' => 'phpArray', 'base_dir' => 'path/to/language', 'pattern' => '%s.php'],
        ['type' => 'gettext', 'base_dir' => 'path/to/language', 'pattern' => '%s.mo'],
    ],
]);

TranslatorRegistry::register('default', $translator);

// Use helpers
use function Seworqs\Commons\I18n\t;
use function Seworqs\Commons\I18n\t2;
use function Seworqs\Commons\I18n\tc;

echo t('welcome.message');
echo t2('item.one', 'item.many', 5);
echo tc('errors', 'not_found');
```

Creating Your Own Translatable Enums
------------------------------------

[](#creating-your-own-translatable-enums)

You can define your own enum like this:

```
use Seworqs\Commons\I18n\Contract\TranslatableEnumInterface;
use Seworqs\Commons\I18n\Traits\TranslatableEnumTrait;

enum Status: string implements TranslatableEnumInterface
{
    use TranslatableEnumTrait;

    case APPROVED = 'approved';
    case DECLINED = 'declined';

    public static function getTranslationPrefix(): string
    {
        return 'enum.status';
    }

    public static function getTextDomain(): string
    {
        return 'enum';
    }
}
```

Features
--------

[](#features)

- Combine multiple translation back-ends (PHP-array, Gettext) into a single composite translator
- Implement region→language→final locale fallback (e.g. nl\_BE → nl → en)
- Provide standalone (createStandAlone) and PSR-11 (\_\_invoke) translation factories
- Include global helper functions (t(), t2(), tc()) for fast, in-code translations with placeholder and context support
- Offer a centralized TranslatorRegistry with a sensible default key for global access
- Load translations via configurable translation\_file\_patterns — PHP-array files or Gettext .mo files
- Leverage PHP 8.1 modern features: constructor property promotion, readonly properties, strict types, and return declarations
- Extensible architecture: add custom TranslatorInterface implementations or tweak fallback logic via decorators

License
-------

[](#license)

Apache-2.0 — see [LICENSE](./LICENSE)

About SEworqs
-------------

[](#about-seworqs)

SEworqs builds clean, reusable modules for PHP and Mendix developers. Learn more at [github.com/seworqs](https://github.com/seworqs)

Badges
------

[](#badges)

[![Latest Version](https://camo.githubusercontent.com/2dc79264228e9e69da58ac92a67afa28f85e8873ee15771093207a5e27ceb42e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7365776f7271732f636f6d6d6f6e732d6931386e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/seworqs/commons-i18n)[![Total Downloads](https://camo.githubusercontent.com/6a41486389919655c090faea4b4fe8612e710772f09c3991448767a70e21a88f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7365776f7271732f636f6d6d6f6e732d6931386e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/seworqs/commons-i18n)[![License](https://camo.githubusercontent.com/2b0dfa032c42e2e16a3a2eec022d9b29340348c39e0dda1aa108fa3ef15a1f44/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7365776f7271732f636f6d6d6f6e732d6931386e3f7374796c653d666c61742d737175617265)](https://packagist.org/packages/seworqs/commons-i18n)[![PHP Version](https://camo.githubusercontent.com/ab677feb15e9a6d483c0e4e652970077ced636b79e3180e09f5aec2ec1bfd9be/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7365776f7271732f636f6d6d6f6e732d6931386e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/seworqs/commons-i18n)[![Made by SEworqs](https://camo.githubusercontent.com/d261914a774b546f4f5b1e9a121baff37ed64b3909f9f940b655bbc7ad9bb50b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6d61646525323062792d5345776f7271732d3030326437343f7374796c653d666c61742d737175617265)](https://github.com/seworqs)

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance50

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

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 ~3 days

Total

3

Last Release

361d ago

Major Versions

1.0.0 → 2.0.02025-05-12

### Community

Maintainers

![](https://www.gravatar.com/avatar/4a83a01e1305cbd8007675b4271d06b7d3680f4e9ddc447186632d2c05982cdd?d=identicon)[seworqs](/maintainers/seworqs)

---

Top Contributors

[![seworqs-sefranke](https://avatars.githubusercontent.com/u/205894657?v=4)](https://github.com/seworqs-sefranke "seworqs-sefranke (4 commits)")

---

Tags

i18nlanguagetranslationseworqs

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/seworqs-commons-i18n/health.svg)

```
[![Health](https://phpackages.com/badges/seworqs-commons-i18n/health.svg)](https://phpackages.com/packages/seworqs-commons-i18n)
```

###  Alternatives

[tractorcow/silverstripe-fluent

Simple localisation for Silverstripe

92421.6k26](/packages/tractorcow-silverstripe-fluent)[badinansoft/nova-language-switch

A Laravel Nova package to switch language in your application

26506.4k1](/packages/badinansoft-nova-language-switch)[inpsyde/multilingual-press

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

2414.0k1](/packages/inpsyde-multilingual-press)[fisharebest/localization

A lightweight localization database and translation tools, with data from the CLDR, IANA, ISO, etc.

3191.1k2](/packages/fisharebest-localization)[delight-im/i18n

Internationalization and localization for PHP

625.2k3](/packages/delight-im-i18n)[jrmajor/fluent

Fluent localization system for PHP

2716.9k5](/packages/jrmajor-fluent)

PHPackages © 2026

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