Skip to content

Commit d698654

Browse files
author
Igor Chepurnoy
committed
added translations: en, ru
1 parent 824b097 commit d698654

File tree

8 files changed

+196
-9
lines changed

8 files changed

+196
-9
lines changed

README.md

+25-1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,30 @@ echo \yii2mod\comments\widgets\Comment::widget([
114114
]);
115115
```
116116

117+
## Internationalization
118+
119+
All text and messages introduced in this extension are translatable under category 'yii2mod.comments'.
120+
You may use translations provided within this extension, using following application configuration:
121+
122+
```php
123+
return [
124+
'components' => [
125+
'i18n' => [
126+
'translations' => [
127+
'yii2mod.comments' => [
128+
'class' => 'yii\i18n\PhpMessageSource',
129+
'basePath' => '@yii2mod/comments/messages',
130+
],
131+
// ...
132+
],
133+
],
134+
// ...
135+
],
136+
// ...
137+
];
138+
```
139+
140+
117141
#### Example comments
118142
-----
119-
![Alt text](http://res.cloudinary.com/zfort/image/upload/v1467214676/comments-preview.png "Example comments")
143+
![Alt text](http://res.cloudinary.com/zfort/image/upload/v1467214676/comments-preview.png "Example comments")

controllers/DefaultController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function actionCreate($entity)
7979
public function actionDelete($id)
8080
{
8181
if ($this->findModel($id)->deleteComment()) {
82-
return Yii::t('yii2mod.comments', 'Comment was deleted.');
82+
return Yii::t('yii2mod.comments', 'Comment has been deleted.');
8383
} else {
8484
Yii::$app->response->setStatusCode(500);
8585
return Yii::t('yii2mod.comments', 'Comment has not been deleted. Please try again!');

messages/config.php

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

messages/en/yii2mod.comments.php

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Message translations.
4+
*
5+
* This file is automatically generated by 'yii message' command.
6+
* It contains the localizable messages extracted from source code.
7+
* You may modify this file by translating the extracted messages.
8+
*
9+
* Each array element represents the translation (value) of a message (key).
10+
* If the value is empty, the message is considered as not translated.
11+
* Messages that no longer need translation will have their translations
12+
* enclosed between a pair of '@@' marks.
13+
*
14+
* Message string can be used with plural forms format. Check i18n section
15+
* of the guide for details.
16+
*
17+
* NOTE: this file must be saved in UTF-8 encoding.
18+
*/
19+
return [
20+
'ID' => 'ID',
21+
'Content' => 'Content',
22+
'Entity' => 'Entity',
23+
'Entity ID' => 'Entity ID',
24+
'Parent ID' => 'Parent ID',
25+
'Status' => 'Status',
26+
'Level' => 'Level',
27+
'Created by' => 'Created by',
28+
'Updated by' => 'Related to',
29+
'Related to' => 'Related to',
30+
'Created date' => 'Created date',
31+
'Updated date' => 'Updated date',
32+
'Update' => 'Update',
33+
'Delete' => 'Delete',
34+
'Reply' => 'Reply',
35+
'Comments ({0})' => 'Comments ({0})',
36+
'Comment cannot be blank.' => 'Comment cannot be blank.',
37+
'Comment has not been deleted. Please try again!' => 'Comment has not been deleted. Please try again!',
38+
'Add a comment...' => 'Add a comment...',
39+
'Comment' => 'Comment',
40+
'Oops, something went wrong. Please try again later.' => 'Oops, something went wrong. Please try again later.',
41+
'The requested page does not exist.' => 'The requested page does not exist.',
42+
'Comment has been deleted.' => 'Comment has been deleted.',
43+
'Comment has been saved.' => 'Comment has been saved.',
44+
'Click here to cancel reply.' => 'Click here to cancel reply.',
45+
'Comments Management' => 'Comments Management',
46+
'Select Status' => 'Select Status',
47+
'Select Author' => 'Select Author',
48+
'Update Comment: {0}' => 'Update Comment: {0}',
49+
'Active' => 'Active',
50+
'Deleted' => 'Deleted'
51+
];

messages/ru/yii2mod.comments.php

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Message translations.
4+
*
5+
* This file is automatically generated by 'yii message' command.
6+
* It contains the localizable messages extracted from source code.
7+
* You may modify this file by translating the extracted messages.
8+
*
9+
* Each array element represents the translation (value) of a message (key).
10+
* If the value is empty, the message is considered as not translated.
11+
* Messages that no longer need translation will have their translations
12+
* enclosed between a pair of '@@' marks.
13+
*
14+
* Message string can be used with plural forms format. Check i18n section
15+
* of the guide for details.
16+
*
17+
* NOTE: this file must be saved in UTF-8 encoding.
18+
*/
19+
return [
20+
'ID' => 'ИД',
21+
'Content' => 'Комментарий',
22+
'Entity' => 'Модель',
23+
'Entity ID' => 'ИД модели',
24+
'Parent ID' => 'Родитель',
25+
'Status' => 'Статус',
26+
'Level' => 'Уровень',
27+
'Created by' => 'Создан',
28+
'Updated by' => 'Обновлен',
29+
'Related to' => 'Относится к',
30+
'Created date' => 'Дата создания',
31+
'Updated date' => 'Дата обновления',
32+
'Update' => 'Обновить',
33+
'Delete' => 'Удалить',
34+
'Reply' => 'Ответить',
35+
'Comments ({0})' => 'Комментарии ({0})',
36+
'Comment cannot be blank.' => 'Комментарий не может быть пустым.',
37+
'Comment has not been deleted. Please try again!' => 'Не удалось удалить комментарий. Попробуйте пожалуйста еще раз!',
38+
'Add a comment...' => 'Добавить комментарий...',
39+
'Comment' => 'Опубликовать комментарий',
40+
'Oops, something went wrong. Please try again later.' => 'Не удалось добавить комментарий. Попробуйте пожалуйста еще раз.',
41+
'The requested page does not exist.' => 'Ошибка 404 - страница не найдена!',
42+
'Comment has been deleted.' => 'Комментарий был удалён.',
43+
'Comment has been saved.' => 'Комментарий был сохранён.',
44+
'Click here to cancel reply.' => 'Нажмите здесь, чтобы отменить ответ.',
45+
'Comments Management' => 'Управление Комментариями',
46+
'Select Status' => 'Выберите Статус',
47+
'Select Author' => 'Выберите Автора',
48+
'Update Comment: {0}' => 'Обновить комментарий: {0}',
49+
'Active' => 'Включён',
50+
'Deleted' => 'Удален'
51+
];

models/CommentModel.php

+8-5
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ public static function tableName()
5353
public function rules()
5454
{
5555
return [
56-
[['entity', 'entityId', 'content'], 'required'],
56+
[['entity', 'entityId'], 'required'],
57+
['content', 'required', 'message' => Yii::t('yii2mod.comments', 'Comment cannot be blank.')],
5758
[['content', 'entity', 'relatedTo'], 'string'],
5859
['parentId', 'validateParentID'],
5960
[['entityId', 'parentId', 'createdBy', 'updatedBy', 'status', 'createdAt', 'updatedAt', 'level'], 'integer'],
@@ -113,8 +114,10 @@ public function attributeLabels()
113114
{
114115
return [
115116
'id' => Yii::t('yii2mod.comments', 'ID'),
116-
'content' => Yii::t('yii2mod.comments', 'Comment'),
117+
'content' => Yii::t('yii2mod.comments', 'Content'),
117118
'entity' => Yii::t('yii2mod.comments', 'Entity'),
119+
'entityId' => Yii::t('yii2mod.comments', 'Entity ID'),
120+
'parentId' => Yii::t('yii2mod.comments', 'Parent ID'),
118121
'status' => Yii::t('yii2mod.comments', 'Status'),
119122
'level' => Yii::t('yii2mod.comments', 'Level'),
120123
'createdBy' => Yii::t('yii2mod.comments', 'Created by'),
@@ -168,7 +171,7 @@ public function afterSave($insert, $changedAttributes)
168171
self::updateAll(['status' => CommentStatus::DELETED], ['parentId' => $this->id]);
169172
}
170173
}
171-
174+
172175
parent::afterSave($insert, $changedAttributes);
173176
}
174177

@@ -323,9 +326,9 @@ public function getAuthorName()
323326
* @param string $deletedCommentText
324327
* @return string
325328
*/
326-
public function getContent($deletedCommentText = 'Comment was deleted.')
329+
public function getContent($deletedCommentText = 'Comment has been deleted.')
327330
{
328-
return $this->isDeleted ? $deletedCommentText : nl2br($this->content);
331+
return $this->isDeleted ? Yii::t('yii2mod.comments', $deletedCommentText) : nl2br($this->content);
329332
}
330333

331334
/**

views/manage/update.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/* @var $model \yii2mod\comments\models\CommentModel */
1010
/* @var $form yii\widgets\ActiveForm */
1111

12-
$this->title = Yii::t('yii2mod.comments', 'Update Comment: ') . $model->id;
12+
$this->title = Yii::t('yii2mod.comments', 'Update Comment: {0}', $model->id);
1313
$this->params['breadcrumbs'][] = ['label' => Yii::t('yii2mod.comments', 'Comments Management'), 'url' => ['index']];
1414
$this->params['breadcrumbs'][] = Yii::t('yii2mod.comments', 'Update');
1515
?>

widgets/views/_list.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<?php if ($comment->isActive): ?>
2020
<div class="comment-action-buttons">
2121
<?php if (Yii::$app->getUser()->can('admin')): ?>
22-
<?php echo Html::a('<span class="glyphicon glyphicon-trash"></span> Delete', '#', ['data' => ['action' => 'delete', 'url' => Url::to(['/comment/default/delete', 'id' => $comment->id]), 'comment-id' => $comment->id]]); ?>
22+
<?php echo Html::a('<span class="glyphicon glyphicon-trash"></span> ' . Yii::t('yii2mod.comments', 'Delete'), '#', ['data' => ['action' => 'delete', 'url' => Url::to(['/comment/default/delete', 'id' => $comment->id]), 'comment-id' => $comment->id]]); ?>
2323
<?php endif; ?>
2424
<?php if (!Yii::$app->user->isGuest && ($comment->level < $maxLevel || is_null($maxLevel))): ?>
2525
<?php echo Html::a("<span class='glyphicon glyphicon-share-alt'></span> " . Yii::t('yii2mod.comments', 'Reply'), '#', ['class' => 'comment-reply', 'data' => ['action' => 'reply', 'comment-id' => $comment->id]]); ?>

0 commit comments

Comments
 (0)