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

ActiveCakephp-plugin[Localization &amp; i18n](/categories/localization)

bedita/i18n
===========

Internationalization plugin for BEdita &amp; CakePHP

v6.1.0(3mo ago)3113.4k↑11.9%1[1 PRs](https://github.com/bedita/i18n/pulls)9LGPL-3.0-or-laterPHPPHP &gt;=8.3CI passing

Since Sep 17Pushed 3mo ago5 watchersCompare

[ Source](https://github.com/bedita/i18n)[ Packagist](https://packagist.org/packages/bedita/i18n)[ RSS](/packages/bedita-i18n/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (10)Dependencies (19)Versions (65)Used By (9)

I18n plugin for BEdita &amp; CakePHP
====================================

[](#i18n-plugin-for-bedita--cakephp)

[![Github Actions](https://github.com/bedita/i18n/workflows/php/badge.svg)](https://github.com/bedita/i18n/actions?query=workflow%3Aphp)[![codecov](https://camo.githubusercontent.com/f16ee4f1052343c5e556e7b2d18a076977f9cd6ee30a4c672005b9474cb6f560/68747470733a2f2f636f6465636f762e696f2f67682f6265646974612f6931386e2f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/bedita/i18n)[![phpstan](https://camo.githubusercontent.com/ec7738978bfba8ff45587516cd33023146ab0888dd11d4658be565ec9f2b37b1/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c253230342d627269676874677265656e2e737667)](https://phpstan.org)[![psalm](https://camo.githubusercontent.com/c9399531f83db9ad38eace5e32a5d3e3382a79f64223deea86d32c3355952ecf/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7073616c6d2d6c6576656c253230382d627269676874677265656e2e737667)](https://psalm.dev)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/89d9b014c1cf25e86f7a8b037aae5bdf57144e128812d9b9a21134e18e5c423f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6265646974612f6931386e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/bedita/i18n?branch=master)[![image](https://camo.githubusercontent.com/7556894d5fe2f9d61a09e7d71e07042709bd12e3290ce42f4d356def24d7407c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6265646974612f6931386e2e7376673f6c6162656c3d737461626c65)](https://packagist.org/packages/bedita/i18n)[![image](https://camo.githubusercontent.com/7a38e9414c553d6831d84d790958fd5e81967ec18530cb8207d2943774e1019e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6265646974612f6931386e2e737667)](https://github.com/bedita/i18n/blob/master/LICENSE.LGPL)

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

[](#installation)

You can install this BEdita/CakePHP plugin using [composer](http://getcomposer.org) like this:

```
composer require bedita/i18n
```

Setup
-----

[](#setup)

In order to use the plugin you have to load it in your `Application::bootstrap()` using

```
$this->addPlugin('BEdita/I18n');
```

Middleware and Helper
---------------------

[](#middleware-and-helper)

First of all you need to setup an `I18n` configuration in your application `config/bootstrap.php` (or if you prefer in `config/app_local.php`)

```
/*
 * I18n configuration.
 */
Configure::write('I18n', [
    // list of locales supported
    // locale => primary language code for that locale
    'locales' => [
        'en_US' => 'en',
        'it_IT' => 'it',
    ],
    // default primary language code
    'default' => 'en',
    // list of languages supported
    // primary language code => humanized language
    'languages' => [
        'en' => 'English',
        'it' => 'Italiano',
    ],

    /** Middleware specific conf **/
    // array of URL paths, if there's an exact match rule is applied
    'match' => ['/'],
    // array of URL paths, if current URL path starts with one of these rule is applied
    'startWith' => ['/help', '/about'],
    //reserved URL (for example `/lang`) used to switch language and redirect to referer URL.
    'switchLangUrl' => '/lang',
    // array for cookie that keeps the locale value. By default no cookie is used.
    'cookie' => [
         'name' =>  'i18n-lang', //cookie name
         'create' => true, // set to `true` if the middleware is responsible of cookie creation
         'expire' => '+1 year', // used when `create` is `true` to define when the cookie must expire
    ],
    // session key where store the locale. Set null to disable (default)
    'sessionKey' => 'i18n-session-locale',
]);
```

### I18nMiddleware

[](#i18nmiddleware)

Adding `BEdita/I18n` plugin in app `Application::bootstrap()` method, the `I18nMiddleware`will be added in middleware queue just before `RoutingMiddleware`.

`I18n` configuration will be used to setup middleware configuration.

```
namespace App;

use Cake\Http\BaseApplication;

/**
 * Application setup class.
 */
class Application extends BaseApplication
{
    /**
     * {inheritDoc}
     */
    public function bootstrap(): void
    {
        parent::bootstrap();

        $this->addPlugin('BEdita/I18n');
    }

    // other stuff here
}
```

You can also decide to not add `I18nMiddleware` since your app doesn't need it or to programmatically add it in your application:

```
namespace App;

use BEdita\I18n\Middleware\I18nMiddleware;
use Cake\Http\BaseApplication;
use Cake\Error\Middleware\ErrorHandlerMiddleware;
use Cake\Http\MiddlewareQueue;
use Cake\Routing\Middleware\AssetMiddleware;
use Cake\Routing\Middleware\RoutingMiddleware;

/**
 * Application setup class.
 */
class Application extends BaseApplication
{
    /**
     * {inheritDoc}
     */
    public function bootstrap(): void
    {
        parent::bootstrap();

        // Do not add I18nMiddleware automatically
        $this->addPlugin('BEdita/I18n', ['middleware' => false]);
    }

    /**
     * {@inheritDoc}
     */
    public function middleware($middlewareQueue) : MiddlewareQueue
    {
        $middlewareQueue
            ->add(ErrorHandlerMiddleware::class)
            ->add(AssetMiddleware::class)

            // Add programmatically I18n middleware.
            ->add(new I18nMiddleware())

            ->add(new RoutingMiddleware($this));

        return $middlewareQueue;
    }
}
```

In this way the middleware just takes care of setup the right locale using the URI path and a configuration. For example navigating to  the middleware setup locale to `it_IT`using the above configuration example.

You can configure the middleware to redirect some urls to their i18n versions

```
$middlewareQueue->add(new I18nMiddleware([
    'match' => ['/'],
    'startWith' => ['/help/', '/about/'],
]));
```

All URI paths matching exactly something in `'match'` key or starting with one entry in `'startWith'`will be redirect to the same URL but with the detected language as prefix, for example `/it/help`.

You can also configure the middleware to use a cookie to store the locale

```
$middlewareQueue->add(new I18nMiddleware([
    'cookie' =>[
        'name' => 'I18nLocale',
        'create' => true, // the middleware will create the cookie (default false)
        'expire' => '+1 month', // cookie expiring time (default +1 year)
    ],
]));
```

### I18nRoute

[](#i18nroute)

`I18nRoute` class can be used to simplify the way you write and match routing rules. For example

```
$routes->connect(
    '/pages',
    [
        'controller' => 'Pages',
        'action' => 'index',
    ],
    [
        '_name' => 'pages:index',
        'routeClass' => 'BEdita/I18n.I18nRoute',
    ]
);
```

maps to `/:lang/pages` and the language code defined in `I18n.languages` configuration will be used as route patterns on `:lang` param.

So the above rule is the same of

```
$routes->connect(
    '/:lang/pages',
    [
        'controller' => 'Pages',
        'action' => 'index',
    ],
    ['_name' => 'pages:index']
)
->setPatterns(['lang' => 'it|en']);
```

If the current language is `it` you can obtain the localized url as

```
// default
$url = \Cake\Routing\Router::url(['_name' => 'pages:index']);
echo $url; // prints /it/pages

// get url with another supported lang
$url = \Cake\Routing\Router::url([
    '_name' => 'pages:index',
    'lang' => 'en',
]);
echo $url; // prints /en/pages
```

### I18nHelper

[](#i18nhelper)

In order to use the helper you need to initialize it in your `AppView::initialize()` method

```
public function initialize() : void
{
    parent::initialize();

    $this->loadHelper('BEdita/I18n.I18n');
}
```

Gettext command
---------------

[](#gettext-command)

`gettext` command provides a method to update I18N locale files in BEdita apps and plugins.

A working `msgmerge` binary on your system is necessary. In most Linux systems this is provided via `gettext` package.

By simply typing

```
bin/cake gettext
```

your code inside `/src` and `/config` is parsed and gettext strings are extracted looking for `__('Some string')` expressions. Then:

- `resources/locales/default.pot` gettext master file is created or updated, same for optional domain files like `mydomain.pot`
- all locale files like `resources/locales/{locale}/default.po` and other optional domain files like `mydomain.po` are also created or updated - where `{locale}` is the usual locale expression like `en-US`, `de-DE` or `fr-FR`.

Command options:

```
--help, -h      Display this help.
--quiet, -q     Enable quiet output.
--verbose, -v   Enable verbose output.
--app, -a       The app path, for i18n update.
--plugin, -p    The plugin path, for i18n update.
--plugins       Apply on all plugins.
```

You may invoke this command on a different application or plugin path via `--app` or `--plugin` options.

###  Health Score

63

—

FairBetter than 99% of packages

Maintenance82

Actively maintained with recent releases

Popularity35

Limited adoption so far

Community28

Small or concentrated contributor base

Maturity91

Battle-tested with a long release history

 Bus Factor2

2 contributors hold 50%+ of commits

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

Recently: every ~114 days

Total

64

Last Release

95d ago

Major Versions

v3.5.1 → v4.1.42022-06-13

v3.5.2 → v4.1.52022-07-19

1.x-dev → v4.2.22022-10-21

v4.4.3 → v5.0.02024-12-03

5.x-dev → v6.0.02025-03-06

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

v3.0.0PHP &gt;=7.2

v4.0.0PHP &gt;=7.4

v5.0.0PHP &gt;=8.1

v5.1.0PHP &gt;=8.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/877076?v=4)[Mugdin Hasanbegovic](/maintainers/bato)[@Bato](https://github.com/Bato)

![](https://www.gravatar.com/avatar/33c95e1516af3f48ebb2057caafd7f331a7aaae58c52442f8e8d00e03b211da9?d=identicon)[stefanorosanelli](/maintainers/stefanorosanelli)

![](https://www.gravatar.com/avatar/8762bf55fa377228164991afe77ca94b7384eb1f5ed79781cad7835624cc27c3?d=identicon)[d.didomenico](/maintainers/d.didomenico)

---

Top Contributors

[![didoda](https://avatars.githubusercontent.com/u/2227145?v=4)](https://github.com/didoda "didoda (90 commits)")[![stefanorosanelli](https://avatars.githubusercontent.com/u/2122280?v=4)](https://github.com/stefanorosanelli "stefanorosanelli (80 commits)")[![batopa](https://avatars.githubusercontent.com/u/1306319?v=4)](https://github.com/batopa "batopa (73 commits)")[![fquffio](https://avatars.githubusercontent.com/u/7108146?v=4)](https://github.com/fquffio "fquffio (15 commits)")[![edoardocavazza](https://avatars.githubusercontent.com/u/3907295?v=4)](https://github.com/edoardocavazza "edoardocavazza (5 commits)")[![le0m](https://avatars.githubusercontent.com/u/10656716?v=4)](https://github.com/le0m "le0m (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[cakephp/cakephp

The CakePHP framework

8.8k19.1M1.7k](/packages/cakephp-cakephp)[tempest/framework

The PHP framework that gets out of your way.

2.2k31.1k11](/packages/tempest-framework)[cakephp/authentication

Authentication plugin for CakePHP

1153.9M95](/packages/cakephp-authentication)[typo3/cms

TYPO3 CMS is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.

1.2k1.9M122](/packages/typo3-cms)[flarum/core

Delightfully simple forum software.

261.4M2.2k](/packages/flarum-core)[typo3/cms-core

TYPO3 CMS Core

3312.9M4.7k](/packages/typo3-cms-core)

PHPackages © 2026

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