Commit 3eb90c54 by Luciano Baraglia

Enable I18N for GII model generator

parent 7c36fa93
......@@ -115,9 +115,9 @@ yii.gii = (function ($) {
$('#model-generator .field-generator-modelclass').toggle($(this).val().indexOf('*') == -1);
}).change();
// CRUD generator: hide messageCategory when I18N is disabled
$('#crud-generator #generator-enablei18n').change(function () {
$('#crud-generator .field-generator-messagecategory').toggle($(this).is(':checked'));
// hide message category when I18N is disabled
$('form #generator-enablei18n').change(function () {
$('form .field-generator-messagecategory').toggle($(this).is(':checked'));
}).change();
// hide Generate button if any input is changed
......
......@@ -64,6 +64,8 @@ class Generator extends \yii\gii\Generator
[['modelClass'], 'validateModelClass', 'skipOnEmpty' => false],
[['baseClass'], 'validateClass', 'params' => ['extends' => ActiveRecord::className()]],
[['generateRelations', 'generateLabelsFromComments'], 'boolean'],
[['enableI18N'], 'boolean'],
[['messageCategory'], 'validateMessageCategory', 'skipOnEmpty' => false],
]);
}
......@@ -72,7 +74,7 @@ class Generator extends \yii\gii\Generator
*/
public function attributeLabels()
{
return [
return array_merge(parent::attributeLabels(), [
'ns' => 'Namespace',
'db' => 'Database Connection ID',
'tableName' => 'Table Name',
......@@ -80,7 +82,7 @@ class Generator extends \yii\gii\Generator
'baseClass' => 'Base Class',
'generateRelations' => 'Generate Relations',
'generateLabelsFromComments' => 'Generate Labels from DB Comments',
];
]);
}
/**
......@@ -88,7 +90,7 @@ class Generator extends \yii\gii\Generator
*/
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>',
'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>.
......@@ -107,7 +109,7 @@ class Generator extends \yii\gii\Generator
you may want to uncheck this option to accelerate the code generation process.',
'generateLabelsFromComments' => 'This indicates whether the generator should generate attribute labels
by using the comments of the corresponding DB columns.',
];
]);
}
/**
......@@ -140,7 +142,7 @@ class Generator extends \yii\gii\Generator
*/
public function stickyAttributes()
{
return ['ns', 'db', 'baseClass', 'generateRelations', 'generateLabelsFromComments'];
return array_merge(parent::stickyAttributes(), ['ns', 'db', 'baseClass', 'generateRelations', 'generateLabelsFromComments']);
}
/**
......
......@@ -55,7 +55,7 @@ class <?= $className ?> extends <?= '\\' . ltrim($generator->baseClass, '\\') .
{
return [
<?php foreach ($labels as $name => $label): ?>
<?= "'$name' => '" . addslashes($label) . "',\n" ?>
<?= "'$name' => " . $generator->generateString($label) . ",\n" ?>
<?php endforeach; ?>
];
}
......
......@@ -12,3 +12,5 @@ echo $form->field($generator, 'baseClass');
echo $form->field($generator, 'db');
echo $form->field($generator, 'generateRelations')->checkbox();
echo $form->field($generator, 'generateLabelsFromComments')->checkbox();
echo $form->field($generator, 'enableI18N')->checkbox();
echo $form->field($generator, 'messageCategory');
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment