Skip to content

Commit 070391d

Browse files
author
Igor Chepurnoy
committed
add messages
1 parent 99b2742 commit 070391d

File tree

13 files changed

+121
-46
lines changed

13 files changed

+121
-46
lines changed

controllers/SiteController.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ public function behaviors()
3232
'index' => ['get'],
3333
'contact' => ['get', 'post'],
3434
'account' => ['get', 'post'],
35+
'login' => ['get', 'post'],
3536
'logout' => ['post'],
36-
],
37+
'signup' => ['get', 'post'],
38+
'request-password-reset' => ['get', 'post'],
39+
'password-reset' => ['get', 'post'],
40+
'page' => ['get', 'post']
41+
]
3742
],
3843
];
3944
}
@@ -91,9 +96,9 @@ public function actionContact()
9196
$model = new ContactForm();
9297
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
9398
if ($model->sendEmail(Yii::$app->params['adminEmail'])) {
94-
Yii::$app->session->setFlash('success', 'Thank you for contacting us. We will respond to you as soon as possible.');
99+
Yii::$app->session->setFlash('success', Yii::t('user', 'Thank you for contacting us. We will respond to you as soon as possible.'));
95100
} else {
96-
Yii::$app->session->setFlash('error', 'There was an error sending email.');
101+
Yii::$app->session->setFlash('error', Yii::t('user', 'There was an error sending email.'));
97102
}
98103
return $this->refresh();
99104
} else {
@@ -113,7 +118,7 @@ public function actionAccount()
113118
$resetPasswordForm = new ResetPasswordForm($userModel);
114119

115120
if ($resetPasswordForm->load(Yii::$app->request->post()) && $resetPasswordForm->resetPassword()) {
116-
Yii::$app->session->setFlash('success', Yii::t('app', 'Password has been updated.'));
121+
Yii::$app->session->setFlash('success', Yii::t('user', 'Password has been updated.'));
117122
return $this->refresh();
118123
}
119124

@@ -122,5 +127,4 @@ public function actionAccount()
122127
'userModel' => $userModel
123128
]);
124129
}
125-
126-
}
130+
}

messages/config.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
/**
3+
* This is a configuration file for the [[\yii\console\controllers\MessageController]] console command.
4+
*
5+
* In order to update translations, run the following console command:
6+
* php yii message messages/config.php
7+
*
8+
* @see yii\console\controllers\MessageController
9+
*/
10+
return [
11+
// string, required, root directory of all source files
12+
'sourcePath' => __DIR__ . DIRECTORY_SEPARATOR . '..',
13+
// array, required, list of language codes that the extracted messages
14+
// should be translated to. For example, ['zh-CN', 'de'].
15+
'languages' => ['en'],
16+
// string, the name of the function for translating messages.
17+
// Defaults to 'Yii::t'. This is used as a mark to find the messages to be
18+
// translated. You may use a string for single function name or an array for
19+
// multiple function names.
20+
'translator' => 'Yii::t',
21+
// boolean, whether to sort messages by keys when merging new messages
22+
// with the existing ones. Defaults to false, which means the new (untranslated)
23+
// messages will be separated from the old (translated) ones.
24+
'sort' => true,
25+
// boolean, whether to remove messages that no longer appear in the source code.
26+
// Defaults to false, which means each of these messages will be enclosed with a pair of '@@' marks.
27+
'removeUnused' => false,
28+
// array, list of patterns that specify which files (not directories) should be processed.
29+
// If empty or not set, all files will be processed.
30+
// Please refer to "except" for details about the patterns.
31+
'only' => ['*.php'],
32+
// array, list of patterns that specify which files/directories should NOT be processed.
33+
// If empty or not set, all files/directories will be processed.
34+
// A path matches a pattern if it contains the pattern string at its end. For example,
35+
// '/a/b' will match all files and directories ending with '/a/b';
36+
// the '*.svn' will match all files and directories whose name ends with '.svn'.
37+
// and the '.svn' will match all files and directories named exactly '.svn'.
38+
// Note, the '/' characters in a pattern matches both '/' and '\'.
39+
// See helpers/FileHelper::findFiles() description for more details on pattern matching rules.
40+
// If a file/directory matches both a pattern in "only" and "except", it will NOT be processed.
41+
'except' => [
42+
'.svn',
43+
'.git',
44+
'.gitignore',
45+
'.gitkeep',
46+
'.hg',
47+
'.hgignore',
48+
'.hgkeep',
49+
'/assets',
50+
'/messages',
51+
'/migrations',
52+
'/tests',
53+
'/runtime',
54+
'/vendor',
55+
'/web',
56+
'/webstub',
57+
],
58+
// 'php' output format is for saving messages to php files.
59+
'format' => 'php',
60+
// Root directory containing message translations.
61+
'messagePath' => __DIR__,
62+
// boolean, whether the message file should be overwritten with the merged messages
63+
'overwrite' => true,
64+
// Message categories to ignore
65+
'ignoreCategories' => [
66+
'yii'
67+
]
68+
];

models/UserModel.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public function rules()
2323
{
2424
return ArrayHelper::merge([
2525
[['username', 'email'], 'required'],
26-
['email', 'unique', 'message' => 'This email address has already been taken.'],
27-
['username', 'unique', 'message' => 'This username has already been taken.'],
26+
['email', 'unique', 'message' => Yii::t('user', 'This email address has already been taken.')],
27+
['username', 'unique', 'message' => Yii::t('user', 'This username has already been taken.')],
2828
['username', 'string', 'min' => 2, 'max' => 255],
2929
['email', 'email'],
3030
['email', 'string', 'max' => 255],
@@ -39,7 +39,10 @@ public function rules()
3939
public function attributeLabels()
4040
{
4141
return ArrayHelper::merge([
42-
'newPassword' => $this->isNewRecord ? Yii::t('app', 'Password') : Yii::t('app', 'New Password'),
42+
'username' => Yii::t('user', 'Username'),
43+
'email' => Yii::t('user', 'Email'),
44+
'createdAt' => Yii::t('user', 'Created date'),
45+
'newPassword' => $this->isNewRecord ? Yii::t('user', 'Password') : Yii::t('user', 'New Password'),
4346
], parent::attributeLabels());
4447
}
4548

models/forms/ContactForm.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ public function rules()
3737
public function attributeLabels()
3838
{
3939
return [
40-
'verifyCode' => 'Verification Code',
40+
'name' => Yii::t('contact', 'Name'),
41+
'email' => Yii::t('contact', 'Email'),
42+
'subject' => Yii::t('contact', 'Subject'),
43+
'body' => Yii::t('contact', 'Body'),
44+
'verifyCode' => Yii::t('contact', 'Verification Code'),
4145
];
4246
}
4347

models/forms/ResetPasswordForm.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ public function rules()
6565
public function attributeLabels()
6666
{
6767
return [
68-
'password' => Yii::t('app', 'New Password'),
69-
'confirmPassword' => Yii::t('app', 'Confirm New Password'),
68+
'password' => Yii::t('user', 'New Password'),
69+
'confirmPassword' => Yii::t('user', 'Confirm New Password'),
7070
];
7171
}
7272

modules/admin/Module.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,27 @@
1111
class Module extends \yii\base\Module
1212
{
1313
/**
14-
* Default route
15-
* @var string
14+
* @var string the default route of this module. Defaults to 'default'.
1615
*/
1716
public $defaultRoute = 'user';
1817

1918
/**
20-
* Default layout
21-
* @var string
19+
* @var string|boolean the layout that should be applied for views within this module.
2220
*/
2321
public $layout = 'column2';
2422

2523
/**
26-
* Controller namespace
27-
* @var string
24+
* @var string the namespace that controller classes are in.
2825
*/
2926
public $controllerNamespace = 'app\modules\admin\controllers';
3027

3128
/**
32-
* Init module
29+
* @return array
3330
*/
34-
public function init()
31+
public function behaviors()
3532
{
36-
$this->attachBehavior(AccessControl::className(), new AccessControl());
37-
parent::init();
33+
return [
34+
AccessControl::className()
35+
];
3836
}
39-
40-
}
37+
}

modules/admin/controllers/UserController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function actions()
6262
'findModel' => function ($id) {
6363
return $this->findModel(UserModel::className(), $id);
6464
},
65-
'flash' => 'User has been deleted.'
65+
'flash' => Yii::t('user', 'User has been deleted.')
6666
],
6767
];
6868
}
@@ -80,7 +80,7 @@ public function actionCreate()
8080

8181
if ($model->load(Yii::$app->request->post())) {
8282
if ($model->createUser()) {
83-
Yii::$app->session->setFlash('success', 'User has been created.');
83+
Yii::$app->session->setFlash('success', Yii::t('user', 'User has been created.'));
8484
return $this->redirect(['index']);
8585
}
8686
}
@@ -107,7 +107,7 @@ public function actionUpdate($id)
107107
$model->setPassword($model->newPassword);
108108
}
109109
$model->save(false);
110-
Yii::$app->session->setFlash('success', 'User has been saved.');
110+
Yii::$app->session->setFlash('success', Yii::t('user', 'User has been saved.'));
111111
return $this->redirect(['index']);
112112
}
113113

modules/admin/views/user/_form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
</div>
2727

2828
<div class="form-group">
29-
<?php echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
29+
<?php echo Html::submitButton($model->isNewRecord ? Yii::t('user', 'Create') : Yii::t('user', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
3030
</div>
3131

3232
<?php ActiveForm::end(); ?>

modules/admin/views/user/create.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
/* @var $this yii\web\View */
66
/* @var $model app\models\UserModel */
77

8-
$this->title = 'Create User';
9-
$this->params['breadcrumbs'][] = ['label' => 'Users', 'url' => ['index']];
8+
$this->title = Yii::t('user', 'Create User');
9+
$this->params['breadcrumbs'][] = ['label' => Yii::t('user', 'Users'), 'url' => ['index']];
1010
$this->params['breadcrumbs'][] = $this->title;
1111
?>
1212
<div class="user-create">

modules/admin/views/user/index.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
/* @var $dataProvider yii\data\ActiveDataProvider */
1111
/* @var $searchModel \app\models\UserModelSearch */
1212

13-
$this->title = 'Users';
13+
$this->title = Yii::t('user', 'Users');
1414
$this->params['breadcrumbs'][] = $this->title;
1515
?>
1616
<div class="user-index">
1717

1818
<h1><?php echo Html::encode($this->title) ?></h1>
1919

2020
<p>
21-
<?php echo Html::a('Create User', ['create'], ['class' => 'btn btn-success']) ?>
21+
<?php echo Html::a(Yii::t('user', 'Create User'), ['create'], ['class' => 'btn btn-success']) ?>
2222
</p>
2323
<?php Pjax::begin(['enablePushState' => false, 'timeout' => 10000]); ?>
2424
<?php echo GridView::widget([
@@ -47,16 +47,15 @@
4747
];
4848
},
4949
'filter' => UserStatus::listData(),
50-
'filterInputOptions' => ['prompt' => 'Select Status', 'class' => 'form-control'],
50+
'filterInputOptions' => ['prompt' => Yii::t('user', 'Select Status'), 'class' => 'form-control'],
5151
],
5252
[
5353
'attribute' => 'createdAt',
54-
'label' => 'Created date',
5554
'format' => 'date',
5655
'filter' => false,
5756
],
5857
[
59-
'header' => 'Action',
58+
'header' => Yii::t('user', 'Action'),
6059
'class' => 'yii\grid\ActionColumn',
6160
'template' => '{update}{delete}',
6261
],

modules/admin/views/user/update.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
/* @var $this yii\web\View */
66
/* @var $model app\models\UserModel */
77

8-
$this->title = 'Update User: ' . ' ' . $model->username;
9-
$this->params['breadcrumbs'][] = ['label' => 'Users', 'url' => ['index']];
10-
$this->params['breadcrumbs'][] = 'Update';
8+
$this->title = Yii::t('user', 'Update User: {0}', $model->username);
9+
$this->params['breadcrumbs'][] = ['label' => Yii::t('user', 'Users'), 'url' => ['index']];
10+
$this->params['breadcrumbs'][] = Yii::t('user', 'Update');
1111
?>
1212
<div class="user-update">
1313

views/site/account.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@
77
/* @var $resetPasswordForm \app\models\forms\ResetPasswordForm */
88
/* @var $userModel \app\models\UserModel */
99

10-
$this->title = 'My Account';
10+
$this->title = Yii::t('user', 'My Account');
1111
?>
1212
<div class="container">
1313
<div class="row">
1414
<div class="col-md-6">
1515
<div class="panel panel-default">
1616
<div class="panel-heading">
17-
<?php echo Yii::t('app', 'Change Password'); ?>
17+
<?php echo Yii::t('user', 'Change Password'); ?>
1818
</div>
1919

2020
<div class="panel-body">
2121
<?php $form = ActiveForm::begin(); ?>
2222
<?php echo $form->field($resetPasswordForm, 'password')->passwordInput(); ?>
2323
<?php echo $form->field($resetPasswordForm, 'confirmPassword')->passwordInput(); ?>
2424
<div class="form-group">
25-
<?php echo Html::resetButton('Cancel', ['class' => 'btn btn-default']) ?>
26-
<?php echo Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
25+
<?php echo Html::resetButton(Yii::t('user', 'Cancel'), ['class' => 'btn btn-default']) ?>
26+
<?php echo Html::submitButton(Yii::t('user', 'Save'), ['class' => 'btn btn-success']) ?>
2727
</div>
2828
<?php ActiveForm::end(); ?>
2929
</div>
@@ -32,7 +32,7 @@
3232
<div class="col-md-6">
3333
<div class="panel panel-default">
3434
<div class="panel-heading no-bottom-border">
35-
<?php echo Yii::t('app', 'Personal Information'); ?>
35+
<?php echo Yii::t('user', 'Personal Information'); ?>
3636
</div>
3737
<div class="table-responsive">
3838
<?php echo DetailView::widget([

views/site/contact.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
/* @var $form yii\bootstrap\ActiveForm */
99
/* @var $model app\models\forms\ContactForm */
1010

11-
$this->title = 'Contact';
11+
$this->title = Yii::t('contact', 'Contact');
1212
$this->params['breadcrumbs'][] = $this->title;
1313
?>
1414
<div class="site-contact">
1515
<h1><?php echo Html::encode($this->title) ?></h1>
1616
<p>
17-
If you have business inquiries or other questions, please fill out the following form to contact us. Thank you.
17+
<?php echo Yii::t('contact', 'If you have business inquiries or other questions, please fill out the following form to contact us. Thank you.'); ?>
1818
</p>
1919
<div class="row">
2020
<div class="col-lg-5">
@@ -27,7 +27,7 @@
2727
'template' => '<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>',
2828
]); ?>
2929
<div class="form-group">
30-
<?php echo Html::submitButton('Submit', ['class' => 'btn btn-primary', 'name' => 'contact-button']); ?>
30+
<?php echo Html::submitButton(Yii::t('contact', 'Submit'), ['class' => 'btn btn-primary', 'name' => 'contact-button']); ?>
3131
</div>
3232
<?php ActiveForm::end(); ?>
3333
</div>

0 commit comments

Comments
 (0)