Enable I18N for GII model generator

This commit is contained in:
Luciano Baraglia
2014-03-21 02:47:16 -03:00
parent 7c36fa9356
commit 3eb90c54c1
4 changed files with 13 additions and 9 deletions

View File

@@ -115,9 +115,9 @@ yii.gii = (function ($) {
$('#model-generator .field-generator-modelclass').toggle($(this).val().indexOf('*') == -1); $('#model-generator .field-generator-modelclass').toggle($(this).val().indexOf('*') == -1);
}).change(); }).change();
// CRUD generator: hide messageCategory when I18N is disabled // hide message category when I18N is disabled
$('#crud-generator #generator-enablei18n').change(function () { $('form #generator-enablei18n').change(function () {
$('#crud-generator .field-generator-messagecategory').toggle($(this).is(':checked')); $('form .field-generator-messagecategory').toggle($(this).is(':checked'));
}).change(); }).change();
// hide Generate button if any input is changed // hide Generate button if any input is changed

View File

@@ -64,6 +64,8 @@ class Generator extends \yii\gii\Generator
[['modelClass'], 'validateModelClass', 'skipOnEmpty' => false], [['modelClass'], 'validateModelClass', 'skipOnEmpty' => false],
[['baseClass'], 'validateClass', 'params' => ['extends' => ActiveRecord::className()]], [['baseClass'], 'validateClass', 'params' => ['extends' => ActiveRecord::className()]],
[['generateRelations', 'generateLabelsFromComments'], 'boolean'], [['generateRelations', 'generateLabelsFromComments'], 'boolean'],
[['enableI18N'], 'boolean'],
[['messageCategory'], 'validateMessageCategory', 'skipOnEmpty' => false],
]); ]);
} }
@@ -72,7 +74,7 @@ class Generator extends \yii\gii\Generator
*/ */
public function attributeLabels() public function attributeLabels()
{ {
return [ return array_merge(parent::attributeLabels(), [
'ns' => 'Namespace', 'ns' => 'Namespace',
'db' => 'Database Connection ID', 'db' => 'Database Connection ID',
'tableName' => 'Table Name', 'tableName' => 'Table Name',
@@ -80,7 +82,7 @@ class Generator extends \yii\gii\Generator
'baseClass' => 'Base Class', 'baseClass' => 'Base Class',
'generateRelations' => 'Generate Relations', 'generateRelations' => 'Generate Relations',
'generateLabelsFromComments' => 'Generate Labels from DB Comments', 'generateLabelsFromComments' => 'Generate Labels from DB Comments',
]; ]);
} }
/** /**
@@ -88,7 +90,7 @@ class Generator extends \yii\gii\Generator
*/ */
public function hints() public function hints()
{ {
return [ return array_merge(parent::hints(), [
'ns' => 'This is the namespace of the ActiveRecord class to be generated, e.g., <code>app\models</code>', 'ns' => 'This is the namespace of the ActiveRecord class to be generated, e.g., <code>app\models</code>',
'db' => 'This is the ID of the DB application component.', 'db' => 'This is the ID of the DB application component.',
'tableName' => 'This is the name of the DB table that the new ActiveRecord class is associated with, e.g. <code>tbl_post</code>. 'tableName' => 'This is the name of the DB table that the new ActiveRecord class is associated with, e.g. <code>tbl_post</code>.
@@ -107,7 +109,7 @@ class Generator extends \yii\gii\Generator
you may want to uncheck this option to accelerate the code generation process.', you may want to uncheck this option to accelerate the code generation process.',
'generateLabelsFromComments' => 'This indicates whether the generator should generate attribute labels 'generateLabelsFromComments' => 'This indicates whether the generator should generate attribute labels
by using the comments of the corresponding DB columns.', by using the comments of the corresponding DB columns.',
]; ]);
} }
/** /**
@@ -140,7 +142,7 @@ class Generator extends \yii\gii\Generator
*/ */
public function stickyAttributes() public function stickyAttributes()
{ {
return ['ns', 'db', 'baseClass', 'generateRelations', 'generateLabelsFromComments']; return array_merge(parent::stickyAttributes(), ['ns', 'db', 'baseClass', 'generateRelations', 'generateLabelsFromComments']);
} }
/** /**

View File

@@ -55,7 +55,7 @@ class <?= $className ?> extends <?= '\\' . ltrim($generator->baseClass, '\\') .
{ {
return [ return [
<?php foreach ($labels as $name => $label): ?> <?php foreach ($labels as $name => $label): ?>
<?= "'$name' => '" . addslashes($label) . "',\n" ?> <?= "'$name' => " . $generator->generateString($label) . ",\n" ?>
<?php endforeach; ?> <?php endforeach; ?>
]; ];
} }

View File

@@ -12,3 +12,5 @@ echo $form->field($generator, 'baseClass');
echo $form->field($generator, 'db'); echo $form->field($generator, 'db');
echo $form->field($generator, 'generateRelations')->checkbox(); echo $form->field($generator, 'generateRelations')->checkbox();
echo $form->field($generator, 'generateLabelsFromComments')->checkbox(); echo $form->field($generator, 'generateLabelsFromComments')->checkbox();
echo $form->field($generator, 'enableI18N')->checkbox();
echo $form->field($generator, 'messageCategory');