summaryrefslogtreecommitdiff
path: root/src/Helpers/Translation/GettextTranslator.php
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2019-07-08 01:47:01 +0200
committerIgor Scheller <igor.scheller@igorshp.de>2019-07-08 01:58:06 +0200
commit508695efb253d7bc0caea1fa017ed5608d774596 (patch)
tree857fe3f34a8264df52f57a2ac539b038a2bfb85c /src/Helpers/Translation/GettextTranslator.php
parentf90ab26feedb61615bde2f94bbf5acc7e4f28342 (diff)
Replaced gettext translation with package
This allows to check if no translation is available
Diffstat (limited to 'src/Helpers/Translation/GettextTranslator.php')
-rw-r--r--src/Helpers/Translation/GettextTranslator.php53
1 files changed, 53 insertions, 0 deletions
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 @@
+<?php
+
+namespace Engelsystem\Helpers\Translation;
+
+use Gettext\Translator;
+
+class GettextTranslator extends Translator
+{
+ /**
+ * @param string $domain
+ * @param string $context
+ * @param string $original
+ * @return string
+ * @throws TranslationNotFound
+ */
+ public function dpgettext($domain, $context, $original)
+ {
+ $this->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]));
+ }
+}