Skip to content

Commit 4282dc1

Browse files
Add translations
1 parent 4c4a154 commit 4282dc1

File tree

8 files changed

+75
-3
lines changed

8 files changed

+75
-3
lines changed

.gitignore

100644100755
File mode changed.

Base/YesNot.php

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class YesNot extends Enum
2727
public static function all(): array
2828
{
2929
return [
30-
self::YES => \Yii::t('app', 'Yes'),
31-
self::NOT => \Yii::t('app', 'Not'),
30+
self::YES => \Yii::t('kkd-enum', 'Yes'),
31+
self::NOT => \Yii::t('kkd-enum', 'Not'),
3232
];
3333
}
3434
}

Enum.php

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ abstract class Enum
1919
*
2020
* @var array
2121
*/
22-
protected static $notSetMessage = ['app', 'Не указано'];
22+
protected static $notSetMessage = ['kkd-enum', 'Not set'];
2323

2424
/**
2525
* Enum model attribute name

EnumTranslation.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: mikhail
5+
* Date: 03.12.2018
6+
* Time: 12:44
7+
*/
8+
9+
namespace Kakadu\Yii2Enum;
10+
11+
use yii\helpers\ArrayHelper;
12+
13+
/**
14+
* Trait EnumTranslation
15+
* @package Kakadu\Yii2Enum
16+
* @author Yarmaliuk Mikhail
17+
* @version 1.0
18+
*/
19+
trait EnumTranslation
20+
{
21+
/**
22+
* Get translation config
23+
*
24+
* @param array $default
25+
*
26+
* @return array
27+
*/
28+
public static function getConfig(array $default = []): array
29+
{
30+
\Yii::setAlias('@kkd-enum', dirname(__FILE__));
31+
32+
return ArrayHelper::merge([
33+
'class' => \yii\i18n\PhpMessageSource::class,
34+
'basePath' => '@kkd-enum/messages',
35+
'sourceLanguage' => 'en-US',
36+
'forceTranslation' => true,
37+
], $default);
38+
}
39+
}

LICENSE

100644100755
File mode changed.

README.md

100644100755
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,13 @@ DetailView::widget([
130130
$form->field($model, 'status')->dropDownList(UserStatus::all())
131131
```
132132

133+
Add translation (e.g. in main.php):
134+
```php
135+
'i18n' => [
136+
'translations' => [
137+
'kkd-enum*' => \Kakadu\Yii2Enum\EnumTranslation::getConfig(),
138+
],
139+
],
140+
```
141+
133142
That's all. Check it.

composer.json

100644100755
File mode changed.

messages/ru/kkd-enum.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/**
4+
* Message translations.
5+
*
6+
* This file is automatically generated by 'yii message' command.
7+
* It contains the localizable messages extracted from source code.
8+
* You may modify this file by translating the extracted messages.
9+
*
10+
* Each array element represents the translation (value) of a message (key).
11+
* If the value is empty, the message is considered as not translated.
12+
* Messages that no longer need translation will have their translations
13+
* enclosed between a pair of '@@' marks.
14+
*
15+
* Message string can be used with plural forms format. Check i18n section
16+
* of the guide for details.
17+
*
18+
* NOTE: this file must be saved in UTF-8 encoding.
19+
*/
20+
return [
21+
'Yes' => 'Да',
22+
'Not' => 'Нет',
23+
'Not set' => 'Не указано',
24+
];

0 commit comments

Comments
 (0)