Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
c1fac6eb
Commit
c1fac6eb
authored
Mar 21, 2014
by
Luciano Baraglia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More changes in GII I18N
parent
311bd469
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
46 additions
and
29 deletions
+46
-29
Generator.php
extensions/gii/Generator.php
+38
-4
gii.js
extensions/gii/assets/gii.js
+2
-2
Generator.php
extensions/gii/generators/crud/Generator.php
+4
-21
search.php
extensions/gii/generators/crud/default/search.php
+1
-1
form.php
extensions/gii/generators/crud/form.php
+1
-1
No files found.
extensions/gii/Generator.php
View file @
c1fac6eb
...
...
@@ -47,6 +47,15 @@ abstract class Generator extends Model
* The value of this property is internally managed by this class.
*/
public
$template
;
/**
* @var boolean whether the strings will be generated using `Yii::t()` or normal strings.
*/
public
$enableI18N
=
false
;
/**
* @var string the message category used by `Yii::t()` when `$enableI18N` is `true`.
* Defaults to `app`.
*/
public
$messageCategory
=
'app'
;
/**
* @return string name of the code generator
...
...
@@ -76,6 +85,17 @@ abstract class Generator extends Model
}
/**
* @inheritdoc
*/
public
function
attributeLabels
()
{
return
[
'enableI18N'
=>
'Enable I18N'
,
'messageCategory'
=>
'Message Category'
,
];
}
/**
* Returns a list of code template files that are required.
* Derived classes usually should override this method if they require the existence of
* certain template files.
...
...
@@ -95,7 +115,7 @@ abstract class Generator extends Model
*/
public
function
stickyAttributes
()
{
return
[
'template'
];
return
[
'template'
,
'enableI18N'
,
'messageCategory'
];
}
/**
...
...
@@ -106,7 +126,11 @@ abstract class Generator extends Model
*/
public
function
hints
()
{
return
[];
return
[
'enableI18N'
=>
'This indicates whether the generator should generate strings using <code>Yii::t()</code> method.
Set this to <code>true</code> if you are planning to make your application translatable.'
,
'messageCategory'
=>
'This is the category used by <code>Yii::t()</code> in case you enable I18N.'
,
];
}
/**
...
...
@@ -359,6 +383,16 @@ abstract class Generator extends Model
}
/**
* Checks if message category is not empty when I18N is enabled.
*/
public
function
validateMessageCategory
()
{
if
(
$this
->
enableI18N
&&
empty
(
$this
->
messageCategory
))
{
$this
->
addError
(
'messageCategory'
,
"Message Category cannot be blank."
);
}
}
/**
* @param string $value the attribute to be validated
* @return boolean whether the value is a reserved PHP keyword.
*/
...
...
@@ -454,7 +488,7 @@ abstract class Generator extends Model
* @param string $string the text be generated
* @param array $placeholders the placeholders to use by `Yii::t()`
*/
public
function
generateString
(
$string
=
''
,
$placeholders
=
[]){
public
function
generateString
(
$string
=
''
,
$placeholders
=
[])
{
if
(
$this
->
enableI18N
)
{
// If there are placeholders, use them
if
(
!
empty
(
$placeholders
))
{
...
...
@@ -464,7 +498,7 @@ abstract class Generator extends Model
}
else
{
$ph
=
''
;
}
$str
=
"Yii::t('"
.
$this
->
translation
Category
.
"', '"
.
$string
.
"'"
.
$ph
.
")"
;
$str
=
"Yii::t('"
.
$this
->
message
Category
.
"', '"
.
$string
.
"'"
.
$ph
.
")"
;
}
else
{
// No I18N, replace placeholders by real words, if any
if
(
!
empty
(
$placeholders
))
{
...
...
extensions/gii/assets/gii.js
View file @
c1fac6eb
...
...
@@ -115,9 +115,9 @@ yii.gii = (function ($) {
$
(
'#model-generator .field-generator-modelclass'
).
toggle
(
$
(
this
).
val
().
indexOf
(
'*'
)
==
-
1
);
}).
change
();
// CRUD generator: hide
translation
Category when I18N is disabled
// CRUD generator: hide
message
Category when I18N is disabled
$
(
'#crud-generator #generator-enablei18n'
).
change
(
function
()
{
$
(
'#crud-generator .field-generator-
translation
category'
).
toggle
(
$
(
this
).
is
(
':checked'
));
$
(
'#crud-generator .field-generator-
message
category'
).
toggle
(
$
(
this
).
is
(
':checked'
));
}).
change
();
// hide Generate button if any input is changed
...
...
extensions/gii/generators/crud/Generator.php
View file @
c1fac6eb
...
...
@@ -36,8 +36,6 @@ class Generator extends \yii\gii\Generator
public
$baseControllerClass
=
'yii\web\Controller'
;
public
$indexWidgetType
=
'grid'
;
public
$searchModelClass
;
public
$enableI18N
=
false
;
public
$translationCategory
=
'app'
;
/**
* @inheritdoc
...
...
@@ -74,7 +72,7 @@ class Generator extends \yii\gii\Generator
[[
'modelClass'
],
'validateModelClass'
],
[[
'moduleID'
],
'validateModuleID'
],
[[
'enableI18N'
],
'boolean'
],
[[
'
translationCategory'
],
'validateTranslation
Category'
,
'skipOnEmpty'
=>
false
],
[[
'
messageCategory'
],
'validateMessage
Category'
,
'skipOnEmpty'
=>
false
],
]);
}
...
...
@@ -90,8 +88,6 @@ class Generator extends \yii\gii\Generator
'baseControllerClass'
=>
'Base Controller Class'
,
'indexWidgetType'
=>
'Widget Used in Index Page'
,
'searchModelClass'
=>
'Search Model Class'
,
'enableI18N'
=>
'Enable I18N'
,
'translationCategory'
=>
'Translation Category'
,
]);
}
...
...
@@ -100,7 +96,7 @@ class Generator extends \yii\gii\Generator
*/
public
function
hints
()
{
return
[
return
array_merge
(
parent
::
hints
(),
[
'modelClass'
=>
'This is the ActiveRecord class associated with the table that CRUD will be built upon.
You should provide a fully qualified class name, e.g., <code>app\models\Post</code>.'
,
'controllerClass'
=>
'This is the name of the controller class to be generated. You should
...
...
@@ -113,10 +109,7 @@ class Generator extends \yii\gii\Generator
You may choose either <code>GridView</code> or <code>ListView</code>'
,
'searchModelClass'
=>
'This is the name of the search model class to be generated. You should provide a fully
qualified namespaced class name, e.g., <code>app\models\search\PostSearch</code>.'
,
'enableI18N'
=>
'This indicates whether the generator should generate strings using <code>Yii::t()</code> method.
Set this to <code>true</code> if you are planning to make your application translatable.'
,
'translationCategory'
=>
'This is the category used by <code>Yii::t()</code> in case you enable I18N.'
,
];
]);
}
/**
...
...
@@ -132,7 +125,7 @@ class Generator extends \yii\gii\Generator
*/
public
function
stickyAttributes
()
{
return
[
'baseControllerClass'
,
'moduleID'
,
'indexWidgetType'
,
'enableI18N'
,
'translationCategory'
]
;
return
array_merge
(
parent
::
stickyAttributes
(),
[
'baseControllerClass'
,
'moduleID'
,
'indexWidgetType'
])
;
}
/**
...
...
@@ -162,16 +155,6 @@ class Generator extends \yii\gii\Generator
}
/**
* Checks if translation category is not empty when I18N is enabled
*/
public
function
validateTranslationCategory
()
{
if
(
$this
->
enableI18N
&&
empty
(
$this
->
translationCategory
))
{
$this
->
addError
(
'translationCategory'
,
"Translation Category cannot be blank."
);
}
}
/**
* @inheritdoc
*/
public
function
generate
()
...
...
extensions/gii/generators/crud/default/search.php
View file @
c1fac6eb
...
...
@@ -49,7 +49,7 @@ class <?= $searchModelClass ?> extends Model
{
return [
<?php
foreach
(
$labels
as
$name
=>
$label
)
:
?>
<?=
"'
$name
' => "
.
addslashes
(
$generator
->
generateString
(
$label
))
.
",
\n
"
?>
<?=
"'
$name
' => "
.
$generator
->
generateString
(
addslashes
(
$label
))
.
",
\n
"
?>
<?php
endforeach
;
?>
];
}
...
...
extensions/gii/generators/crud/form.php
View file @
c1fac6eb
...
...
@@ -15,4 +15,4 @@ echo $form->field($generator, 'indexWidgetType')->dropDownList([
'list'
=>
'ListView'
,
]);
echo
$form
->
field
(
$generator
,
'enableI18N'
)
->
checkbox
();
echo
$form
->
field
(
$generator
,
'
translation
Category'
);
echo
$form
->
field
(
$generator
,
'
message
Category'
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment