cinghie/yii2-dictionary

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

0.3.1 2019-05-09 13:43 UTC

This package is auto-updated.

Last update: 2024-12-08 12:32:56 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'] ?: ''