PHPackages                             vovan-ve/yii2-i18n-json-export - 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. vovan-ve/yii2-i18n-json-export

ActiveYii2-extension[Localization &amp; i18n](/categories/localization)

vovan-ve/yii2-i18n-json-export
==============================

Export and import i18n JSON messages

v1.0.5(7y ago)010MITPHPPHP &gt;=7.0

Since Jul 25Pushed 7y ago1 watchersCompare

[ Source](https://github.com/Vovan-VE/yii2-i18n-json-export)[ Packagist](https://packagist.org/packages/vovan-ve/yii2-i18n-json-export)[ RSS](/packages/vovan-ve-yii2-i18n-json-export/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (1)Versions (8)Used By (0)

Yii2 I18N JSON Export
=====================

[](#yii2-i18n-json-export)

[![Latest Stable Version](https://camo.githubusercontent.com/6683a740be968f8e71832e54366d61f7ecea770d7c3674343e6a2505a237fe3a/68747470733a2f2f706f7365722e707567782e6f72672f766f76616e2d76652f796969322d6931386e2d6a736f6e2d6578706f72742f762f737461626c65)](https://packagist.org/packages/vovan-ve/yii2-i18n-json-export)[![License](https://camo.githubusercontent.com/9f2b73162c57b880322a698f9491845447f5379543a21ec6639f06769c0053c0/68747470733a2f2f706f7365722e707567782e6f72672f766f76616e2d76652f796969322d6931386e2d6a736f6e2d6578706f72742f6c6963656e7365)](https://packagist.org/packages/vovan-ve/yii2-i18n-json-export)

Imagine your project has multiple parts with its own separate I18N translations. That parts may be for example backend, server side of frontend, and client side of frontend.

Of cause, some parts may share some messages, and you sure to provide the same translations for such shared messages:

```
// frontend server side
\Yii::t('app/ui', 'Save')
```

```
// frontend client side
i18n.t('app/ui', 'Save')
```

Solution
--------

[](#solution)

1. Export all translations from all source parts into single merged file per each language.
2. Translate messages for specific language in a single JSON file.
3. Import it back to update existing translations in source parts.

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

[](#installation)

Install through [composer](http://getcomposer.org/):

```
composer require vovan-ve/yii2-i18n-json-export

```

or add to `require` section in your composer.json:

```
"vovan-ve/yii2-i18n-json-export": "~1.0.0"

```

Usage
-----

[](#usage)

Add app configuration like following:

```
'components' => [
    'i18nJsonExport' => [
        'class' => \VovanVE\Yii2I18nJsonExport\Manager::class,
        // list of source drivers
        'sourceDrivers' => [
            [
                'class' => \VovanVE\Yii2I18nJsonExport\drivers\SubdirCategoryPhpDriver::class,
                'path' => '@app/messages',
                // strip category prefix
                //'categoryPrefix' => 'app/',
            ],
        ],
        'exportDriver' => [
            'class' => \VovanVE\Yii2I18nJsonExport\drivers\FlatCategoryDriver::class,
            'path' => '@app/i18n',
            // turn on to bubble empty translations to top
            //'sortEmptyFirst' => true,
        ],
        // whether to import back in same files
        //'overwrite' => true,
    ],
],
```

Use component for example from CLI controller:

```
// @app/commands/I18nDumpController.php:
