1 | <?php |
||
23 | trait TranslatableTrait |
||
24 | { |
||
25 | /** |
||
26 | * @var string[] |
||
27 | */ |
||
28 | private $locales; |
||
29 | |||
30 | /** |
||
31 | * @var string|null |
||
32 | */ |
||
33 | private $fallbackLocale; |
||
34 | |||
35 | /** |
||
36 | * @var FactoryInterface |
||
37 | */ |
||
38 | private $translationFactory; |
||
39 | |||
40 | /** |
||
41 | * @var TranslationInterface[]|Collection |
||
42 | */ |
||
43 | protected $translations; |
||
44 | |||
45 | /** |
||
46 | * @return string|null |
||
47 | */ |
||
48 | 3 | public function getLocale() |
|
49 | { |
||
50 | try { |
||
51 | 3 | return $this->getTranslation()->getLocale(); |
|
52 | 2 | } catch (TranslationNotFoundException $e) { |
|
|
|||
53 | } |
||
54 | 2 | } |
|
55 | |||
56 | /** |
||
57 | * @return string[] |
||
58 | */ |
||
59 | 13 | public function getLocales() |
|
60 | { |
||
61 | 13 | return $this->locales; |
|
62 | } |
||
63 | |||
64 | /** |
||
65 | * @param string[] $locales |
||
66 | */ |
||
67 | 11 | public function setLocales($locales) |
|
68 | { |
||
69 | 11 | $this->locales = $locales; |
|
70 | 11 | } |
|
71 | |||
72 | /** |
||
73 | * @return bool |
||
74 | */ |
||
75 | 7 | public function hasFallbackLocale() |
|
76 | { |
||
77 | 7 | return $this->fallbackLocale !== null; |
|
78 | } |
||
79 | |||
80 | /** |
||
81 | * @return string|null |
||
82 | */ |
||
83 | 7 | public function getFallbackLocale() |
|
84 | { |
||
85 | 7 | return $this->fallbackLocale; |
|
86 | } |
||
87 | |||
88 | /** |
||
89 | * @param string|null $fallbackLocale |
||
90 | */ |
||
91 | 8 | public function setFallbackLocale($fallbackLocale) |
|
92 | { |
||
93 | 8 | $this->fallbackLocale = $fallbackLocale; |
|
94 | 8 | } |
|
95 | |||
96 | /** |
||
97 | * @return FactoryInterface |
||
98 | */ |
||
99 | 6 | public function getTranslationFactory() |
|
100 | { |
||
101 | 6 | return $this->translationFactory; |
|
102 | } |
||
103 | |||
104 | /** |
||
105 | * @param FactoryInterface $translationFactory |
||
106 | */ |
||
107 | 5 | public function setTranslationFactory(FactoryInterface $translationFactory) |
|
108 | { |
||
109 | 5 | $this->translationFactory = $translationFactory; |
|
110 | 5 | } |
|
111 | |||
112 | /** |
||
113 | * @return TranslationInterface[]|Collection |
||
114 | */ |
||
115 | 5 | public function getTranslations() |
|
116 | { |
||
117 | 5 | return $this->translations; |
|
118 | } |
||
119 | |||
120 | /** |
||
121 | * @param bool $allowCreate |
||
122 | * |
||
123 | * @return TranslationInterface |
||
124 | */ |
||
125 | 10 | public function getTranslation($allowCreate = false) |
|
160 | |||
161 | /** |
||
162 | * @param TranslationInterface[]|Collection $translations |
||
163 | */ |
||
164 | public function setTranslations($translations) |
||
165 | { |
||
166 | $this->translations->clear(); |
||
167 | |||
168 | foreach ($translations as $translation) { |
||
169 | $this->addTranslation($translation); |
||
172 | |||
173 | /** |
||
174 | * @param TranslationInterface $translation |
||
175 | */ |
||
176 | 9 | public function addTranslation(TranslationInterface $translation) |
|
183 | |||
184 | /** |
||
185 | * @param TranslationInterface $translation |
||
186 | */ |
||
187 | 2 | public function removeTranslation(TranslationInterface $translation) |
|
193 | |||
194 | 19 | private function initTranslatable() |
|
198 | } |
||
199 |