| Conditions | 3 |
| Paths | 3 |
| Total Lines | 16 |
| Code Lines | 8 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 13 | public function translate(string $text, string $pattern = '/[^{{\}\}]+(?=}})/'): string |
||
| 14 | { |
||
| 15 | preg_match_all($pattern, $text, $matches); |
||
| 16 | |||
| 17 | if (0 === \count($matches[0])) { |
||
| 18 | return $text; |
||
| 19 | } |
||
| 20 | |||
| 21 | $replace_vars = []; |
||
| 22 | |||
| 23 | foreach ($matches[0] as $match) { |
||
| 24 | $var = Str::slug($match, '_'); |
||
| 25 | $replace_vars["{{{$match}}}"] = $this->cache->get("{$this->prefix}_{$var}", "{{$var}}"); |
||
| 26 | } |
||
| 27 | |||
| 28 | return strtr($text, $replace_vars); |
||
| 29 | } |
||
| 38 |