Skip to content

Commit d8b0b2f

Browse files
author
Igor Chepurnoy
committed
added translations: en, ru
1 parent 09b5204 commit d8b0b2f

File tree

7 files changed

+187
-9
lines changed

7 files changed

+187
-9
lines changed

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,30 @@ php yii migrate --migrationPath=@vendor/yii2mod/yii2-cms/migrations
8383
```
8484
> And now you can create your own pages via the admin panel, and access them via the `url` of each page.
8585
86-
**Additional features:**
86+
## Internationalization
87+
88+
All text and messages introduced in this extension are translatable under category 'yii2mod.cms'.
89+
You may use translations provided within this extension, using following application configuration:
90+
91+
```php
92+
return [
93+
'components' => [
94+
'i18n' => [
95+
'translations' => [
96+
'yii2mod.cms' => [
97+
'class' => 'yii\i18n\PhpMessageSource',
98+
'basePath' => '@yii2mod/cms/messages',
99+
],
100+
// ...
101+
],
102+
],
103+
// ...
104+
],
105+
// ...
106+
];
107+
```
108+
109+
##Additional features:
87110

88111
1. You can insert your own widget on the page by the following steps:
89112
* Create the widget and add the static function. For example:

messages/config.php

Lines changed: 58 additions & 0 deletions
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.cms.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
'Url' => 'Url',
22+
'Title' => 'Title',
23+
'Content' => 'Content',
24+
'Status' => 'Status',
25+
'Meta Title' => 'Meta Title',
26+
'Meta Description' => 'Meta Description',
27+
'Meta Keywords' => 'Meta Keywords',
28+
'Comments available' => 'Comments available',
29+
'Date Created' => 'Date Created',
30+
'Date Updated' => 'Date Updated',
31+
'Are comments available on the page?' => 'Are comments available on the page?',
32+
'This one accepts only letters, numbers, dash and slash, i.e. "docs/installation".' => 'This one accepts only letters, numbers, dash and slash, i.e. "docs/installation".',
33+
'Create' => 'Create',
34+
'Update' => 'Update',
35+
'Delete' => 'Delete',
36+
'Go Back' => 'Go Back',
37+
'Enabled' => 'Enabled',
38+
'Disabled' => 'Disabled',
39+
'Update Page: {0}' => 'Update Page: {0}',
40+
'Cms Pages' => 'Cms Pages',
41+
'Create Page' => 'Create Page',
42+
'View Comments' => 'View Comments',
43+
'Select Status' => 'Select Status',
44+
'Select' => 'Select',
45+
'Actions' => 'Actions',
46+
'Page has been created.' => 'Page has been created.',
47+
'Page has been updated.' => 'Page has been updated.',
48+
'Page has been deleted.' => 'Page has been deleted.',
49+
'The requested page does not exist.' => 'The requested page does not exist.'
50+
];

messages/ru/yii2mod.cms.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
'Url' => 'Урл',
22+
'Title' => 'Заголовок',
23+
'Content' => 'Контент',
24+
'Status' => 'Статус',
25+
'Meta Title' => 'Заголовок (Meta title)',
26+
'Meta Description' => 'Описание (Meta Description)',
27+
'Meta Keywords' => 'Ключевые слова (Meta Keywords)',
28+
'Comments available' => 'Комментарии включены',
29+
'Date Created' => 'Дата Создания',
30+
'Date Updated' => 'Дата Обновления',
31+
'Are comments available on the page?' => 'Включить комментарии на странице?',
32+
'This one accepts only letters, numbers, dash and slash, i.e. "docs/installation".' => 'Это поле принимает только буквы, цифры, тире и слеш, например "docs/installation".',
33+
'Create' => 'Создать',
34+
'Update' => 'Обновить',
35+
'Delete' => 'Удалить',
36+
'Go Back' => 'Вернуться',
37+
'Enabled' => 'Включена',
38+
'Disabled' => 'Недоступна',
39+
'Update Page: {0}' => 'Обновить Страницу: {0}',
40+
'Cms Pages' => 'CMS Страницы',
41+
'Create Page' => 'Создать Страницу',
42+
'View Comments' => 'Просмотр Комментариев',
43+
'Select Status' => 'Выберите Статус',
44+
'Select' => 'Выберите',
45+
'Actions' => 'Действия',
46+
'Page has been created.' => 'Страница была сохранён.',
47+
'Page has been updated.' => 'Страница был обновлена.',
48+
'Page has been deleted.' => 'Страница был удалена.',
49+
'The requested page does not exist.' => 'Ошибка 404 - страница не найдена!'
50+
];

views/cms/_form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
<?php echo $form->field($model, 'metaKeywords')->textarea(['rows' => 6]); ?>
3737

38-
<?php echo $form->field($model, 'commentAvailable')->checkbox()->label(Yii::t('app', 'Are comments available on the page?')); ?>
38+
<?php echo $form->field($model, 'commentAvailable')->checkbox()->label(Yii::t('yii2mod.cms', 'Are comments available on the page?')); ?>
3939

4040
<?php echo $form->field($model, 'status')->dropDownList(CmsStatus::listData()); ?>
4141

views/cms/index.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,14 @@
4949
'class' => '\yii2mod\toggle\ToggleColumn',
5050
'attribute' => 'commentAvailable',
5151
'filter' => BooleanEnum::listData(),
52-
'filterInputOptions' => ['prompt' => Yii::t('yii2mod.cms', 'Please Select'), 'class' => 'form-control'],
52+
'filterInputOptions' => ['prompt' => Yii::t('yii2mod.cms', 'Select'), 'class' => 'form-control'],
5353
],
5454
[
5555
'attribute' => 'createdAt',
56-
'value' => function ($model) {
57-
return Yii::$app->formatter->asDate($model->createdAt, 'full');
58-
},
59-
'filter' => false,
56+
'format' => ['date', 'full']
6057
],
6158
[
62-
'header' => 'Actions',
59+
'header' => Yii::t('yii2mod.cms', 'Actions'),
6360
'class' => 'yii\grid\ActionColumn',
6461
'template' => '{view}{update}{delete}',
6562
'buttons' => [

views/cms/update.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/* @var $this yii\web\View */
66
/* @var $model yii2mod\cms\models\CmsModel */
77

8-
$this->title = Yii::t('yii2mod.cms', 'Update Page:') . ' ' . $model->title;
8+
$this->title = Yii::t('yii2mod.cms', 'Update Page: {0}', $model->title);
99
$this->params['breadcrumbs'][] = ['label' => Yii::t('yii2mod.cms', 'Cms Pages'), 'url' => ['index']];
1010
$this->params['breadcrumbs'][] = Yii::t('yii2mod.cms', 'Update');
1111
?>

0 commit comments

Comments
 (0)