PHPackages                             webvimark/multilanguage - 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. webvimark/multilanguage

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

webvimark/multilanguage
=======================

Multilanguage for for yii 2

1.0.0(9y ago)78404[1 issues](https://github.com/webvimark/multilanguage/issues)PHP

Since Oct 5Pushed 9y ago2 watchersCompare

[ Source](https://github.com/webvimark/multilanguage)[ Packagist](https://packagist.org/packages/webvimark/multilanguage)[ RSS](/packages/webvimark-multilanguage/feed)WikiDiscussions master Synced today

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

Mulitilanguage behavior for Yii 2
=================================

[](#mulitilanguage-behavior-for-yii-2)

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist webvimark/multilanguage "*"

```

or add

```
"webvimark/multilanguage": "*"

```

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

Create table for translations (you can find table dumps in folder "data")

In you params.php

```
return [
	...

	'mlConfig'=>[
		'default_language'=>'ru',
		'languages'=>[
			'ru'=>'Русский',
			'en'=>'English',
		],
	],

	...
];
```

In your model

( You also can change languages for this model (different from te ones in params) by defining them here )

```
class Page extends ActiveRecord
{
	use MultiLanguageTrait;

	/**
	* @inheritdoc
	*/
	public function behaviors()
	{
		return [
			...

			'mlBehavior'=>[
				'class'    => MultiLanguageBehavior::className(),
				'mlConfig' => [
					'db_table'         => 'translations_with_string',
					'attributes'       => ['name'],
					'admin_routes'     => [
						'content/page/update',
						'content/page/index',
					],
				],
			],

			...
		];
	}
```

In your Base Controller

```
	public function init()
	{
		MultiLanguageHelper::catchLanguage();
		parent::init();
	}
```

In your config file

```
'urlManager'   => [
		'class'=>MultiLanguageUrlManager::className(),
		'enablePrettyUrl' => true,
		'showScriptName'=>false,
		'rules'=>[

			'/'=>'/view',
			'//'=>'/',
			'/'=>'/',

			'//'=>'//',
			'///'=>'//',

		],
	],
```

In your \_form.php

```
