| Code Coverage | ||||||||||
| Lines | Functions and Methods | Classes and Traits | ||||||||
| Total |  | 100.00% | 7 / 7 |  | 100.00% | 3 / 3 | CRAP |  | 100.00% | 1 / 1 | 
| GettextTranslator |  | 100.00% | 7 / 7 |  | 100.00% | 3 / 3 | 4 |  | 100.00% | 1 / 1 | 
| translate |  | 100.00% | 2 / 2 |  | 100.00% | 1 / 1 | 1 | |||
| translatePlural |  | 100.00% | 2 / 2 |  | 100.00% | 1 / 1 | 1 | |||
| assertHasTranslation |  | 100.00% | 3 / 3 |  | 100.00% | 1 / 1 | 2 | |||
| 1 | <?php | 
| 2 | |
| 3 | declare(strict_types=1); | 
| 4 | |
| 5 | namespace Engelsystem\Helpers\Translation; | 
| 6 | |
| 7 | use Gettext\Translator; | 
| 8 | |
| 9 | class GettextTranslator extends Translator | 
| 10 | { | 
| 11 | /** | 
| 12 | * @throws TranslationNotFound | 
| 13 | */ | 
| 14 | protected function translate(?string $domain, ?string $context, string $original): string | 
| 15 | { | 
| 16 | $this->assertHasTranslation($domain, $context, $original); | 
| 17 | |
| 18 | return parent::translate($domain, $context, $original); | 
| 19 | } | 
| 20 | |
| 21 | /** | 
| 22 | * @throws TranslationNotFound | 
| 23 | */ | 
| 24 | protected function translatePlural( | 
| 25 | ?string $domain, | 
| 26 | ?string $context, | 
| 27 | string $original, | 
| 28 | string $plural, | 
| 29 | int $value | 
| 30 | ): string { | 
| 31 | $this->assertHasTranslation($domain, $context, $original); | 
| 32 | |
| 33 | return parent::translatePlural($domain, $context, $original, $plural, $value); | 
| 34 | } | 
| 35 | |
| 36 | /** | 
| 37 | * @throws TranslationNotFound | 
| 38 | */ | 
| 39 | protected function assertHasTranslation(?string $domain, ?string $context, string $original): void | 
| 40 | { | 
| 41 | if ($this->getTranslation($domain, $context, $original)) { | 
| 42 | return; | 
| 43 | } | 
| 44 | |
| 45 | throw new TranslationNotFound(implode('/', [$domain, $context, $original])); | 
| 46 | } | 
| 47 | } |