Version 1
[yaffs-website] / vendor / drupal / console-core / src / Command / Shared / CommandTrait.php
diff --git a/vendor/drupal/console-core/src/Command/Shared/CommandTrait.php b/vendor/drupal/console-core/src/Command/Shared/CommandTrait.php
new file mode 100644 (file)
index 0000000..705630c
--- /dev/null
@@ -0,0 +1,62 @@
+<?php
+
+/**
+ * @file
+ * Contains Drupal\Console\Core\Command\Shared\CommandTrait.
+ */
+
+namespace Drupal\Console\Core\Command\Shared;
+
+use Drupal\Console\Core\Utils\TranslatorManagerInterface;
+
+/**
+ * Class CommandTrait
+ *
+ * @package Drupal\Console\Core\Command
+ */
+trait CommandTrait
+{
+    /**
+     * @var TranslatorManagerInterface
+     */
+    protected $translator;
+
+    /**
+     * @param $translator
+     */
+    public function setTranslator($translator)
+    {
+        $this->translator = $translator;
+    }
+
+    /**
+     * @param $key string
+     *
+     * @return string
+     */
+    public function trans($key)
+    {
+        if (!$this->translator) {
+            return $key;
+        }
+
+        return $this->translator->trans($key);
+    }
+
+    /**
+     * @inheritdoc
+     */
+    public function getDescription()
+    {
+        $description = sprintf(
+            'commands.%s.description',
+            str_replace(':', '.', $this->getName())
+        );
+
+        if (parent::getDescription()==$description) {
+            return $this->trans($description);
+        }
+
+        return parent::getDescription();
+    }
+}