PHPackages                             devgroup/yii2-polyglot - 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. devgroup/yii2-polyglot

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

devgroup/yii2-polyglot
======================

Yii2 integration for AirBnB Polyglot.js

1.1.1(10y ago)31.9k1MITPHP

Since Nov 24Pushed 9y ago7 watchersCompare

[ Source](https://github.com/DevGroup-ru/yii2-polyglot)[ Packagist](https://packagist.org/packages/devgroup/yii2-polyglot)[ RSS](/packages/devgroup-yii2-polyglot/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (5)Used By (1)

Yii2 integration for Airbnb Polyglot.js
=======================================

[](#yii2-integration-for-airbnb-polyglotjs)

[Polyglot.js](https://github.com/airbnb/polyglot.js) is a tiny and powerful JavaScript i18n library from Airbnb.

This is a yii2-extension that helps integrating polyglot.js into your yii2 application.

Usage
-----

[](#usage)

First install extension through composer:

```
php composer.phar require --prefer-dist devgroup/yii2-polyglot

```

Create directory where you will place your translation js files. For example, if we our app is based on yii2-app-advanced - create directory `common/polyglot.js/`.

Now create your js translation files under this directory. Naming format is `common/polyglot.js/%LANGUAGE%.js`, where `%LANGUAGE%` is your `Yii::$app->language`, for example `common/polyglot.js/ru-RU.js`.

An example of js file contents(:en: version file `common/polyglot.js/en-US.js`:

```
polyglot.extend({
  "nav": {
    "hello": "Hello",
    "hello_name": "Hello, %{name}",
    "sidebar": {
      "welcome": "Welcome"
    }
  }
});
```

And an example for 🇷🇺 version file `common/polyglot.js/ru-RU.js`:

```
polyglot.extend({
  "nav": {
    "hello": "Привет",
    "hello_name": "Привет, %{name}",
    "sidebar": {
      "welcome": "Бобро пожаловать"
    }
  }
});
```

Now add a special yii2 application param `PolyglotTranslationPath` with your js translation path as value into your config file(ie. `common/config/params.php`):

```
