Completed
Push — master ( d69358...27ffc6 )
by Dmitry
04:53 queued 53s
created

I18N::translate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 4
dl 0
loc 8
ccs 0
cts 7
cp 0
crap 6
rs 9.4285
1
<?php
2
3
/*
4
 * HiPanel core package
5
 *
6
 * @link      https://hipanel.com/
7
 * @package   hipanel-core
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2014-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hipanel\components;
13
14
class I18N extends \yii\i18n\I18N
15
{
16
    /**
17
     * Removes wrapper `{Lang:text}` that is returned by API
18
     * {@inheritdoc}
19
     */
20
    public function translate($category, $message, $params, $language)
21
    {
22
        if (stripos($message, '{lang:') !== false) {
23
            $message = $this->removeLegacyLangTags($message);
24
        }
25
26
        return parent::translate($category, $message, $params, $language);
27
    }
28
29
    /**
30
     * Unwraps `{Lang:message}`.
31
     * @param $message
32
     * @return string
33
     */
34
    protected function removeLegacyLangTags($message)
35
    {
36
        return preg_replace('/{lang:([^}]*)}/i', '$1', $message);
37
    }
38
}
39