cinghie / yii2-dictionary
Yii2 Dictionary to create, manage, and delete Multilanguage Dictionary in a Yii2 site.
Installs: 224
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 1
Open Issues: 3
Type:yii2-extension
Requires
- ext-zip: *
- cinghie/yii2-traits: @dev
- rodneyrehm/plist: @dev
- yiisoft/yii2: ~2.0.14
This package is auto-updated.
Last update: 2024-12-08 12:32:56 UTC
README
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'] ?: ''