summaryrefslogtreecommitdiffstats
path: root/vendor/gipfl/translation
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/gipfl/translation')
-rw-r--r--vendor/gipfl/translation/LICENSE21
-rw-r--r--vendor/gipfl/translation/composer.json20
-rw-r--r--vendor/gipfl/translation/src/NoTranslator.php11
-rw-r--r--vendor/gipfl/translation/src/StaticTranslator.php31
-rw-r--r--vendor/gipfl/translation/src/TranslationHelper.php37
-rw-r--r--vendor/gipfl/translation/src/TranslatorInterface.php8
-rw-r--r--vendor/gipfl/translation/src/WrapTranslator.php26
7 files changed, 154 insertions, 0 deletions
diff --git a/vendor/gipfl/translation/LICENSE b/vendor/gipfl/translation/LICENSE
new file mode 100644
index 0000000..dd88e09
--- /dev/null
+++ b/vendor/gipfl/translation/LICENSE
@@ -0,0 +1,21 @@
+The MIT License
+
+Copyright (c) 2018 Thomas Gelf
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/vendor/gipfl/translation/composer.json b/vendor/gipfl/translation/composer.json
new file mode 100644
index 0000000..35608bb
--- /dev/null
+++ b/vendor/gipfl/translation/composer.json
@@ -0,0 +1,20 @@
+{
+ "name": "gipfl/translation",
+ "description": "Translation helpers",
+ "type": "library",
+ "license": "MIT",
+ "authors": [
+ {
+ "name": "Thomas Gelf",
+ "email": "thomas@gelf.net"
+ }
+ ],
+ "require": {
+ "php": ">=5.4.0"
+ },
+ "autoload": {
+ "psr-4": {
+ "gipfl\\Translation\\": "src"
+ }
+ }
+}
diff --git a/vendor/gipfl/translation/src/NoTranslator.php b/vendor/gipfl/translation/src/NoTranslator.php
new file mode 100644
index 0000000..3ea64ef
--- /dev/null
+++ b/vendor/gipfl/translation/src/NoTranslator.php
@@ -0,0 +1,11 @@
+<?php
+
+namespace gipfl\Translation;
+
+class NoTranslator implements TranslatorInterface
+{
+ public function translate($string)
+ {
+ return $string;
+ }
+}
diff --git a/vendor/gipfl/translation/src/StaticTranslator.php b/vendor/gipfl/translation/src/StaticTranslator.php
new file mode 100644
index 0000000..d06572b
--- /dev/null
+++ b/vendor/gipfl/translation/src/StaticTranslator.php
@@ -0,0 +1,31 @@
+<?php
+
+namespace gipfl\Translation;
+
+class StaticTranslator
+{
+ /** @var TranslatorInterface */
+ private static $translator;
+
+ public static function get()
+ {
+ if (self::$translator === null) {
+ static::setNoTranslator();
+ }
+
+ return static::$translator;
+ }
+
+ public static function setNoTranslator()
+ {
+ static::set(new NoTranslator());
+ }
+
+ /**
+ * @param TranslatorInterface $translator
+ */
+ public static function set(TranslatorInterface $translator)
+ {
+ self::$translator = $translator;
+ }
+}
diff --git a/vendor/gipfl/translation/src/TranslationHelper.php b/vendor/gipfl/translation/src/TranslationHelper.php
new file mode 100644
index 0000000..02cfdfc
--- /dev/null
+++ b/vendor/gipfl/translation/src/TranslationHelper.php
@@ -0,0 +1,37 @@
+<?php
+
+namespace gipfl\Translation;
+
+trait TranslationHelper
+{
+ /** @var TranslatorInterface */
+ private static $translator;
+
+ /**
+ * @param $string
+ * @param string|null $context
+ * @return string
+ */
+ public function translate($string, $context = null)
+ {
+ return self::getTranslator()->translate($string);
+ }
+
+ public static function getTranslator()
+ {
+ return StaticTranslator::get();
+ }
+
+ public static function setNoTranslator()
+ {
+ StaticTranslator::set(new NoTranslator());
+ }
+
+ /**
+ * @param TranslatorInterface $translator
+ */
+ public static function setTranslator(TranslatorInterface $translator)
+ {
+ StaticTranslator::set($translator);
+ }
+}
diff --git a/vendor/gipfl/translation/src/TranslatorInterface.php b/vendor/gipfl/translation/src/TranslatorInterface.php
new file mode 100644
index 0000000..8026953
--- /dev/null
+++ b/vendor/gipfl/translation/src/TranslatorInterface.php
@@ -0,0 +1,8 @@
+<?php
+
+namespace gipfl\Translation;
+
+interface TranslatorInterface
+{
+ public function translate($string);
+}
diff --git a/vendor/gipfl/translation/src/WrapTranslator.php b/vendor/gipfl/translation/src/WrapTranslator.php
new file mode 100644
index 0000000..d17fcbd
--- /dev/null
+++ b/vendor/gipfl/translation/src/WrapTranslator.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace gipfl\Translation;
+
+class WrapTranslator implements TranslatorInterface
+{
+ /** @var callable */
+ private $callback;
+
+ /** @var TranslatorInterface */
+ private $wrapped;
+
+ public function __construct(TranslatorInterface $wrapped, callable $callback)
+ {
+ $this->wrapped = $wrapped;
+ $this->callback = $callback;
+ }
+
+ public function translate($string)
+ {
+ return call_user_func_array(
+ $this->callback,
+ [$this->wrapped->translate($string)]
+ );
+ }
+}