Conditions | 7 |
Paths | 12 |
Total Lines | 33 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 56 |
Changes | 0 |
1 | <?php |
||
20 | function t($string, array $args = [], $context = null, $language = 'default') |
||
21 | { |
||
22 | if ($context === null) { |
||
23 | $context = I18N::getContext(); |
||
24 | } |
||
25 | |||
26 | //get translation |
||
27 | $translated = I18N::translate($string, $context, $language); |
||
28 | |||
29 | //if there are some arguments |
||
30 | if (empty($args)) { |
||
31 | return $translated; |
||
32 | } |
||
33 | |||
34 | // Transform arguments before inserting them. |
||
35 | foreach ($args as $key => $value) { |
||
36 | switch ($key[0]) { |
||
37 | case '@': |
||
38 | // Escaped only. |
||
39 | $args[$key] = htmlspecialchars($value, ENT_QUOTES, 'UTF-8'); |
||
40 | break; |
||
41 | case '%': |
||
42 | // Escaped and placeholder. |
||
43 | $args[$key] = '<em>' . $value . '</em>'; |
||
44 | break; |
||
45 | case '!': |
||
46 | default: |
||
47 | //do nothing |
||
48 | } |
||
49 | } |
||
50 | |||
51 | return strtr($translated, $args); |
||
52 | } |
||
53 | |||
72 |