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

I18N   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 25
ccs 0
cts 11
cp 0
rs 10
wmc 3
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A translate() 0 8 2
A removeLegacyLangTags() 0 4 1
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