cinghie/yii2-dictionary

Yii2 Dictionary to create, manage, and delete Multilanguage Dictionary in a Yii2 site.

Installs: 108

Dependents: 0

Suggesters: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 3

Type:yii2-extension

0.3.1 2019-05-09 13:43 UTC

README

License Latest Stable Version Latest Release Date Latest Commit Total Downloads

Yii2 Dictionary to create, manage, and delete Multilanguage Dictionary in a Yii2 site.

Features

  • Create a dictionary with key/value: for each key is possible to associate a translation to each language set on config
  • Import from CSV
  • Download as Plist

Installation

The preferred way to install this extension is through composer.

Either run

$ php composer.phar require cinghie/yii2-dictionary "*"

or add

"cinghie/yii2-dictionary": "*"

Create database schema

Run the following command:

$ php yii migrate/up --migrationPath=@vendor/cinghie/yii2-dictionary/migrations

Configuration

Set on your configuration:

// Yii2 Dictionary
'dictionary' => [
	'class' => 'cinghie\dictionary\Dictionary',
	'dictionaryRoles' => ['admin'];
	'languages' => [
		'it-IT' => 'it-IT',
		'en-GB' => 'en-GB',
		'es-ES' => 'es-ES',
		'fr-FR' => 'fr-FR',
		'de-DE' => 'de-DE',
		'ch-CN' => 'ch-CN',
		'pr-PR' => 'pr-PR',
		'ru-RU' => 'ru-RU',
	],
	'showPlistDownload' => true,
	'showTitles' => false,
	'plistFolderPath' => '@webroot/dictionary/plist/';
	'uploadFolderPath' => '@webroot/dictionary/csv/'
	'uploadMaxFileSize' => 5242880
],

Set all language in Tag mode

Filters

If you have a Yii2 App Advanced (frontend/backend) you can exclude frontend actions

'modules' => [ 
	
	'dictionary' => [ 
		'class' => 'cinghie\dictionary\Dictionary',
		'as frontend' => 'cinghie\dictionary\filters\FrontendFilter',
	]
	
],

Overrides

Override controller example, on modules config

'modules' => [ 
	
	'dictionary' => [ 
		'class' => 'cinghie\dictionary\Dictionary',
		'controllerMap' => [
			'keys' => 'app\controllers\KeysController',
		]
	]
	
],

Override models example, on modules config

'modules' => [ 
	
	'dictionary' => [ 
		'class' => 'cinghie\dictionary\Dictionary',
		'modelMap' => [
			'Keys' => 'app\models\Keys'
		]
	]
	
],

Override view example, on components config

'components' => [ 

	'view' => [
		'theme' => [
			'pathMap' => [
				'@cinghie/dictionary/views/keys' => '@app/views/dictionary/keys',
			],
		],
	],
	
],

Get Translation Value

use cinghie\dictionary\models\Keys;

$dictionary = new Keys();

$key   = $dictionary::findOne(KeyID);
$value = $key->getTranslation(LangTag)->attributes['value'] ?: ''