PHPackages                             someson/phalcon-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. someson/phalcon-i18n

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

someson/phalcon-i18n
====================

Multi-lingual support (extended)

v1.3.4(1y ago)51662MITPHPPHP ^8.0|^8.1|^8.2

Since May 10Pushed 1y ago2 watchersCompare

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

READMEChangelog (7)Dependencies (5)Versions (10)Used By (0)

Multi-lingual Support
=====================

[](#multi-lingual-support)

[![GitHub License](https://camo.githubusercontent.com/ca62cc4a00a05d2e80b26e2170420aaf8af53a91a62159732816092670419d01/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f736f6d65736f6e2f7068616c636f6e2d6931386e)](https://camo.githubusercontent.com/ca62cc4a00a05d2e80b26e2170420aaf8af53a91a62159732816092670419d01/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f736f6d65736f6e2f7068616c636f6e2d6931386e)[![CircleCI](https://camo.githubusercontent.com/c07d0a9659ec0b6e5733ac283023b36c3e5a957befd7bd78da48711e4a556346/68747470733a2f2f636972636c6563692e636f6d2f67682f736f6d65736f6e2f7068616c636f6e2d6931386e2f747265652f352e302e7376673f7374796c653d736869656c64)](https://circleci.com/gh/someson/phalcon-i18n/tree/circleci-project-setup)[![codecov](https://camo.githubusercontent.com/11246fee98521261066824e7ccf6dcf647e2c3db7080fdc30eb13b0826d994ee/68747470733a2f2f636f6465636f762e696f2f67682f736f6d65736f6e2f7068616c636f6e2d6931386e2f6272616e63682f352e302f67726170682f62616467652e7376673f746f6b656e3d41573554345755353651)](https://codecov.io/gh/someson/phalcon-i18n)[![Packagist Version (including pre-releases)](https://camo.githubusercontent.com/9d9b454e1b5fec445663474ee4cd81a5f8fc7d31ce0205ac88e281b097499df4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736f6d65736f6e2f7068616c636f6e2d6931386e)](https://camo.githubusercontent.com/9d9b454e1b5fec445663474ee4cd81a5f8fc7d31ce0205ac88e281b097499df4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736f6d65736f6e2f7068616c636f6e2d6931386e)[![Made in Ukraine](https://camo.githubusercontent.com/43115c9fb377039d5dac27be07e5f0e21ea561f4fa1e66ed1aa39e723784ede0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6d6164655f696e2d756b7261696e652d6666643730302e7376673f6c6162656c436f6c6f723d303035376237)](https://supportukrainenow.org/)[![Russian Warship Go Fuck Yourself](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/RussianWarship.svg)](https://stand-with-ukraine.pp.ua)

Extending [Phalcon Framework v5 Translations Module](https://docs.phalcon.io/5.0/en/translate)

Install
-------

[](#install)

```
$ composer require someson/phalcon-i18n
```

Example
-------

[](#example)

e.g. `login.json` File:

```
{
    "form": {
        "label": {
            "identity": "Benutzername",
            "password": "Passwort",
            "rememberMe": "Ich möchte angemeldet bleiben"
        },
        "placeholder": {
            "identity": "Bitte geben Sie ihren Benutzernamen ein",
            "password": "Bitte geben Sie ihr Passwort ein"
        },
        "button": "Anmelden"
    },
    "title": {
        "h1": "Main Title",
        "h2": "some subtitle"
    }
}
```

translating path like `login:form.label.identity` returns `Benutzername`

which start with `login:` means file name and the rest of it is a pure json path.

Usage
-----

[](#usage)

### 1. Simple usage

[](#1-simple-usage)

```
// component using a singleton pattern, so we can instantiate it before the framework itself
// or wrap it into some global function
$t = \Phalcon\I18n\Translator::instance();

// using the "de" directory, "en" by default
$t->setLang('de');

// equal to "global:a", hence "global" is a default scope
echo $t->_('a');

// placeholder "key" replaced through "value"
echo $t->_('b', ['key' => 'value']);

// nested key
echo $t->_('c.d.e', ['key' => 'value']);

// nested key from the "api" scope (filename === scope, if files used)
echo $t->_('api:c.d.e', ['key' => 'value']);
```

### 2. Advanced usage

[](#2-advanced-usage)

in any bootstrap file (i.e. `index.php`) define:

```
use \Phalcon\I18n\Translator;

if (! function_exists('__')) {
    function __(string $key, array $params = [], bool $pluralize = true): string {
        return $key ? Translator::instance()->_($key, $params, $pluralize) : '[TRANSLATION ERROR]';
    }
}
```

inside your code:

```
$translation = __('a.b.c');
```

or in any view:

```

```

```
{{ __('a.b.c') }}
```

Configure
---------

[](#configure)

default config `\Phalcon\I18n\Config\Default.php`:

```
return [
    'defaultLang' => 'en',
    'defaultScope' => 'global',

    // loads data from chosen source (e.g. Json) by chosen loader (e.g. Files)
    // can be e.g. "Mysql" by "Database" (feel free to implement)
    'loader' => [
        'className' => \Phalcon\I18n\Loader\Files::class,
        'arguments' => ['path' => $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'locale'],
    ],

    // reads the source and translates it into chosen type of handler (@see key "handler")
    'adapter' => [
        'className' => \Phalcon\I18n\Adapter\Json::class,
    ],

    // implements \Phalcon\Translate\AdapterInterface
    // returns an object of all translations of the specific language
    // provides functionality for placeholder replacing
    'handler' => [
        'options' => [
            'flatten' => ['shift' => 1],
        ],
    ],

    // replaces user-defined (or '%' by default) placeholders
    'interpolator' => [
        'className' => \Phalcon\I18n\Interpolator\AssocArray::class,
        'arguments' => ['{{', '}}'],
    ],

    // bool only
    'collectMissingTranslations' => true,

    // - false
    // - sprintf pattern e.g. [# %s #]
    // - \Phalcon\I18n\Interfaces\DecoratorInterface object
    'decorateMissingTranslations' => new \Phalcon\I18n\Decorator\HtmlCode,
];
```

you may want to override it with your own config (by default used in `config` container having `i18n` scope):

```
return [
    // ...

    'i18n' => [
        'loader' => [
            'arguments' => ['path' => '/my/own/path/to/locale/'],
        ],
        'interpolator' => [
            'arguments' => ['[[', ']]'],
        ],
        'collectMissingTranslations' => false,
        'decorateMissingTranslations' => '[# %s #]',
    ],

    // ...
];
```

Running Tests
-------------

[](#running-tests)

[Codeception](https://codeception.com/) used

```
$ docker-compose exec i18n ./vendor/bin/codecept build

```

To run tests, run the following command:

```
$ docker-compose exec i18n ./vendor/bin/codecept run [-vv]

```

For code coverage info run

```
$ docker-compose exec i18n ./vendor/bin/codecept run --coverage --coverage-html

```

and open `tests/_output/coverage/index.html` in your browser

### Static analyzer

[](#static-analyzer)

`$ docker-compose exec i18n ./vendor/bin/phpstan analyse src --level max`

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity66

Established project with proven stability

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

Recently: every ~198 days

Total

10

Last Release

558d ago

Major Versions

v1.3.1 → 3.4.x-dev2022-08-28

3.4.x-dev → 4.1.x-dev2022-08-28

v1.3.3 → 5.0.x-dev2024-10-29

PHP version history (5 changes)v1.1PHP &gt;=7.1

v1.2PHP &gt;=7.4

v1.3PHP 8.0.\*

v1.3.3PHP ^8.0

5.0.x-devPHP ^8.0|^8.1|^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/3f2edc4ac8947df09b32cfca2b888ce6f641456c48cb99ec1a9461cdf196ff9c?d=identicon)[someson](/maintainers/someson)

---

Top Contributors

[![someson](https://avatars.githubusercontent.com/u/3097223?v=4)](https://github.com/someson "someson (41 commits)")

---

Tags

i18ninternationalizationphalconphalcon3phalcon4phalcon5phptranslationsi18ntranslatephalcon

###  Code Quality

TestsCodeception

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/someson-phalcon-i18n/health.svg)

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

###  Alternatives

[gettext/languages

gettext languages with plural rules

7530.3M10](/packages/gettext-languages)[punic/punic

PHP-Unicode CLDR

1542.9M29](/packages/punic-punic)[optimistdigital/nova-translatable

A laravel-translatable extension for Laravel Nova.

202427.4k5](/packages/optimistdigital-nova-translatable)[outl1ne/nova-translatable

A laravel-translatable extension for Laravel Nova.

203416.9k8](/packages/outl1ne-nova-translatable)[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)[om/potrans

Command line tool for translate Gettext with Google Translator API or DeepL API

10515.0k4](/packages/om-potrans)

PHPackages © 2026

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