From 508695efb253d7bc0caea1fa017ed5608d774596 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Mon, 8 Jul 2019 01:47:01 +0200 Subject: Replaced gettext translation with package This allows to check if no translation is available --- src/Helpers/Translation/GettextTranslator.php | 53 +++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/Helpers/Translation/GettextTranslator.php (limited to 'src/Helpers/Translation/GettextTranslator.php') diff --git a/src/Helpers/Translation/GettextTranslator.php b/src/Helpers/Translation/GettextTranslator.php new file mode 100644 index 00000000..7f2299e2 --- /dev/null +++ b/src/Helpers/Translation/GettextTranslator.php @@ -0,0 +1,53 @@ +assertHasTranslation($domain, $context, $original); + + return parent::dpgettext($domain, $context, $original); + } + + /** + * @param string $domain + * @param string $context + * @param string $original + * @param string $plural + * @param string $value + * @return string + * @throws TranslationNotFound + */ + public function dnpgettext($domain, $context, $original, $plural, $value) + { + $this->assertHasTranslation($domain, $context, $original); + + return parent::dnpgettext($domain, $context, $original, $plural, $value); + } + + /** + * @param string $domain + * @param string $context + * @param string $original + * @throws TranslationNotFound + */ + protected function assertHasTranslation($domain, $context, $original) + { + if ($this->getTranslation($domain, $context, $original)) { + return; + } + + throw new TranslationNotFound(implode('/', [$domain, $context, $original])); + } +} -- cgit v1.2.3-54-g00ecf