Version 1
[yaffs-website] / web / modules / contrib / devel / webprofiler / src / StringTranslation / TranslationManagerWrapper.php
1 <?php
2
3 namespace Drupal\webprofiler\StringTranslation;
4
5 use Drupal\Core\StringTranslation\TranslationManager;
6
7 /**
8  * Class TranslationManagerWrapper
9  */
10 class TranslationManagerWrapper extends TranslationManager {
11
12   /**
13    * @var \Drupal\webprofiler\StringTranslation\TranslationManagerWrapper
14    */
15   private $translationManager;
16
17   /**
18    * @var array
19    */
20   private $translated;
21
22   /**
23    * @var array
24    */
25   private $untranslated;
26
27   /**
28    * @param \Drupal\webprofiler\StringTranslation\TranslationManagerWrapper $translationManager
29    */
30   public function setDataCollector(TranslationManagerWrapper $translationManager) {
31     $this->translationManager = $translationManager;
32   }
33
34   /**
35    * {@inheritdoc}
36    */
37   protected function doTranslate($string, array $options = array()) {
38     // Merge in defaults.
39     if (empty($options['langcode'])) {
40       $options['langcode'] = $this->defaultLangcode;
41     }
42     if (empty($options['context'])) {
43       $options['context'] = '';
44     }
45     $translation = $this->getStringTranslation($options['langcode'], $string, $options['context']);
46
47     if($translation) {
48       $this->translated[$string] = $translation;
49     } else {
50       $this->untranslated[$string] = $string;
51     }
52
53     return $translation === FALSE ? $string : $translation;
54   }
55
56   /**
57    * @return array
58    */
59   public function getTranslated() {
60     return $this->translated;
61   }
62
63   /**
64    * @return array
65    */
66   public function getUntranslated() {
67     return $this->untranslated;
68   }
69 }