1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kunstmaan\TranslatorBundle\Model\Translation; |
4
|
|
|
|
5
|
|
|
use Kunstmaan\TranslatorBundle\Entity\Translation; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Groups all translations for all languages specified by a key |
9
|
|
|
**/ |
10
|
|
|
class TranslationGroup |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Translation ID |
14
|
|
|
*/ |
15
|
|
|
private $id; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* All translations for a specific key (Kunstmaan\TranslatorBundle\Model\Translation\Translation) |
19
|
|
|
* |
20
|
|
|
* @var Doctrine\Common\Collections\ArrayCollection |
21
|
|
|
**/ |
22
|
|
|
private $translations; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Translation identifier |
26
|
|
|
* |
27
|
|
|
* @var string |
28
|
|
|
**/ |
29
|
|
|
private $keyword; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The domain name of this group |
33
|
|
|
* |
34
|
|
|
**/ |
35
|
|
|
private $domain; |
36
|
|
|
|
37
|
3 |
|
public function __construct() |
38
|
|
|
{ |
39
|
3 |
|
$this->translations = new \Doctrine\Common\Collections\ArrayCollection(); |
|
|
|
|
40
|
3 |
|
} |
41
|
|
|
|
42
|
3 |
|
public function hasTranslation($locale) |
43
|
|
|
{ |
44
|
3 |
|
if (count($this->translations) <= 0) { |
45
|
3 |
|
return false; |
46
|
|
|
} |
47
|
|
|
|
48
|
3 |
|
if ($this->getTranslationByLocale($locale) !== null) { |
49
|
3 |
|
return true; |
50
|
|
|
} |
51
|
|
|
|
52
|
2 |
|
return false; |
53
|
|
|
} |
54
|
|
|
|
55
|
3 |
|
public function getTranslationByLocale($locale) |
|
|
|
|
56
|
|
|
{ |
57
|
3 |
|
if (count($this->translations) <= 0) { |
58
|
|
|
return null; |
59
|
|
|
} |
60
|
|
|
|
61
|
3 |
|
foreach ($this->translations as $translation) { |
62
|
3 |
|
if (strtolower($translation->getLocale()) == strtolower($locale)) { |
63
|
3 |
|
return $translation; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
2 |
|
return null; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getTranslationTextByLocale($locale) |
|
|
|
|
71
|
|
|
{ |
72
|
|
|
$translation = $this->getTranslationByLocale($locale); |
73
|
|
|
|
74
|
|
|
return is_null($translation) ? null : $translation->getText(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function addTranslation(Translation $translation) |
78
|
|
|
{ |
79
|
|
|
$translation->setTranslationId($this->getId()); |
80
|
|
|
$this->translations->add($translation); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function getTranslations() |
84
|
|
|
{ |
85
|
|
|
return $this->translations; |
86
|
|
|
} |
87
|
|
|
|
88
|
3 |
|
public function setTranslations($translations) |
89
|
|
|
{ |
90
|
3 |
|
foreach ($translations as $translation) { |
91
|
3 |
|
$translation->setTranslationId($this->getId()); |
92
|
|
|
} |
93
|
3 |
|
$this->translations = $translations; |
94
|
3 |
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param mixed $id |
98
|
|
|
*/ |
99
|
3 |
|
public function setId($id) |
100
|
|
|
{ |
101
|
3 |
|
$this->id = $id; |
102
|
3 |
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return mixed |
106
|
|
|
*/ |
107
|
3 |
|
public function getId() |
108
|
|
|
{ |
109
|
3 |
|
return $this->id; |
110
|
|
|
} |
111
|
|
|
|
112
|
3 |
|
public function getKeyword() |
113
|
|
|
{ |
114
|
3 |
|
return $this->keyword; |
115
|
|
|
} |
116
|
|
|
|
117
|
3 |
|
public function setKeyword($keyword) |
118
|
|
|
{ |
119
|
3 |
|
$this->keyword = $keyword; |
120
|
3 |
|
} |
121
|
|
|
|
122
|
3 |
|
public function getDomain() |
|
|
|
|
123
|
|
|
{ |
124
|
3 |
|
return $this->domain; |
125
|
|
|
} |
126
|
|
|
|
127
|
3 |
|
public function setDomain($domain) |
128
|
|
|
{ |
129
|
3 |
|
$this->domain = $domain; |
130
|
3 |
|
} |
131
|
|
|
} |
132
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..