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
d54c6159
Commit
d54c6159
authored
Mar 20, 2014
by
Luciano Baraglia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add category for I18N in GII
parent
4827d732
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
13 deletions
+33
-13
Generator.php
extensions/gii/Generator.php
+7
-7
gii.js
extensions/gii/assets/gii.js
+5
-0
Generator.php
extensions/gii/generators/crud/Generator.php
+19
-5
form.php
extensions/gii/generators/crud/form.php
+2
-1
No files found.
extensions/gii/Generator.php
View file @
d54c6159
...
...
@@ -450,12 +450,12 @@ abstract class Generator extends Model
}
/**
* Generates a string depending on
translatable
property
* Generates a string depending on
enableI18N
property
* @param string $string the text be generated
* @param array $placeholders the placeholders to use by `Yii::t()`
*/
public
function
generateString
(
$string
=
''
,
$placeholders
=
[]){
if
(
$this
->
translatable
)
{
if
(
$this
->
enableI18N
)
{
// If there are placeholders, use them
if
(
count
(
$placeholders
)
>
0
)
{
$search
=
[
'array ('
,
')'
];
...
...
@@ -464,20 +464,20 @@ abstract class Generator extends Model
}
else
{
$ph
=
''
;
}
$str
ing
=
"Yii::t('app
', '"
.
$string
.
"'"
.
$ph
.
")"
;
$str
=
"Yii::t('"
.
$this
->
translationCategory
.
"
', '"
.
$string
.
"'"
.
$ph
.
")"
;
}
else
{
// No
translatable
, replace placeholders by real words, if any
// No
I18N
, replace placeholders by real words, if any
if
(
count
(
$placeholders
)
>
0
)
{
$phKeys
=
array_map
(
function
(
$word
)
{
return
'{'
.
$word
.
'}'
;
},
array_keys
(
$placeholders
));
$phValues
=
array_values
(
$placeholders
);
$str
ing
=
"'"
.
str_replace
(
$phKeys
,
$phValues
,
$string
)
.
"'"
;
$str
=
"'"
.
str_replace
(
$phKeys
,
$phValues
,
$string
)
.
"'"
;
}
else
{
// No placeholders, just the given string
$str
ing
=
"'"
.
$string
.
"'"
;
$str
=
"'"
.
$string
.
"'"
;
}
}
return
$str
ing
;
return
$str
;
}
}
extensions/gii/assets/gii.js
View file @
d54c6159
...
...
@@ -115,6 +115,11 @@ yii.gii = (function ($) {
$
(
'#model-generator .field-generator-modelclass'
).
toggle
(
$
(
this
).
val
().
indexOf
(
'*'
)
==
-
1
);
}).
change
();
// CRUD generator: hide translationCategory when I18N is disabled
$
(
'#crud-generator #generator-enablei18n'
).
on
(
'change'
,
function
()
{
$
(
'#crud-generator .field-generator-translationcategory'
).
toggle
(
$
(
this
).
is
(
':checked'
));
}).
change
();
// hide Generate button if any input is changed
$
(
'.default-view .form-group input,select,textarea'
).
change
(
function
()
{
$
(
'.default-view-results,.default-view-files'
).
hide
();
...
...
extensions/gii/generators/crud/Generator.php
View file @
d54c6159
...
...
@@ -36,7 +36,8 @@ class Generator extends \yii\gii\Generator
public
$baseControllerClass
=
'yii\web\Controller'
;
public
$indexWidgetType
=
'grid'
;
public
$searchModelClass
;
public
$translatable
=
false
;
public
$enableI18N
=
false
;
public
$translationCategory
=
'app'
;
/**
* @inheritdoc
...
...
@@ -72,7 +73,8 @@ class Generator extends \yii\gii\Generator
[[
'indexWidgetType'
],
'in'
,
'range'
=>
[
'grid'
,
'list'
]],
[[
'modelClass'
],
'validateModelClass'
],
[[
'moduleID'
],
'validateModuleID'
],
[[
'translatable'
],
'boolean'
],
[[
'enableI18N'
],
'boolean'
],
[[
'translationCategory'
],
'validateTranslationCategory'
,
'skipOnEmpty'
=>
false
],
]);
}
...
...
@@ -88,7 +90,8 @@ class Generator extends \yii\gii\Generator
'baseControllerClass'
=>
'Base Controller Class'
,
'indexWidgetType'
=>
'Widget Used in Index Page'
,
'searchModelClass'
=>
'Search Model Class'
,
'translatable'
=>
'Generate Translatable Strings'
,
'enableI18N'
=>
'Enable I18N'
,
'translationCategory'
=>
'Translation Category'
,
]);
}
...
...
@@ -110,8 +113,9 @@ 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>.'
,
'
translatable
'
=>
'This indicates whether the generator should generate strings using <code>Yii::t()</code> method.
'
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.'
,
];
}
...
...
@@ -128,7 +132,7 @@ class Generator extends \yii\gii\Generator
*/
public
function
stickyAttributes
()
{
return
[
'baseControllerClass'
,
'moduleID'
,
'indexWidgetType'
,
'
translatable
'
];
return
[
'baseControllerClass'
,
'moduleID'
,
'indexWidgetType'
,
'
enableI18N'
,
'translationCategory
'
];
}
/**
...
...
@@ -158,6 +162,16 @@ class Generator extends \yii\gii\Generator
}
/**
* Checks if translation category is not empty when I18N is enabled
*/
public
function
validateTranslationCategory
()
{
if
((
boolean
)
$this
->
enableI18N
&&
empty
(
$this
->
translationCategory
))
{
$this
->
addError
(
'translationCategory'
,
"Translation Category cannot be blank."
);
}
}
/**
* @inheritdoc
*/
public
function
generate
()
...
...
extensions/gii/generators/crud/form.php
View file @
d54c6159
...
...
@@ -14,4 +14,5 @@ echo $form->field($generator, 'indexWidgetType')->dropDownList([
'grid'
=>
'GridView'
,
'list'
=>
'ListView'
,
]);
echo
$form
->
field
(
$generator
,
'translatable'
)
->
checkbox
();
echo
$form
->
field
(
$generator
,
'enableI18N'
)
->
checkbox
();
echo
$form
->
field
(
$generator
,
'translationCategory'
);
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