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
|
|
|
* @var string |
35
|
|
|
**/ |
36
|
|
|
private $domain; |
37
|
|
|
|
38
|
3 |
|
public function __construct() |
39
|
|
|
{ |
40
|
3 |
|
$this->translations = new \Doctrine\Common\Collections\ArrayCollection(); |
|
|
|
|
41
|
3 |
|
} |
42
|
|
|
|
43
|
3 |
|
public function hasTranslation($locale) |
44
|
|
|
{ |
45
|
3 |
|
if (count($this->translations) <= 0) { |
46
|
3 |
|
return false; |
47
|
|
|
} |
48
|
|
|
|
49
|
3 |
|
if ($this->getTranslationByLocale($locale) !== null) { |
50
|
3 |
|
return true; |
51
|
|
|
} |
52
|
|
|
|
53
|
2 |
|
return false; |
54
|
|
|
} |
55
|
|
|
|
56
|
3 |
|
public function getTranslationByLocale($locale) |
|
|
|
|
57
|
|
|
{ |
58
|
3 |
|
if (count($this->translations) <= 0) { |
59
|
|
|
return null; |
60
|
|
|
} |
61
|
|
|
|
62
|
3 |
|
foreach ($this->translations as $translation) { |
63
|
3 |
|
if (strtolower($translation->getLocale()) == strtolower($locale)) { |
64
|
3 |
|
return $translation; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
2 |
|
return null; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function getTranslationTextByLocale($locale) |
|
|
|
|
72
|
|
|
{ |
73
|
|
|
$translation = $this->getTranslationByLocale($locale); |
74
|
|
|
|
75
|
|
|
return is_null($translation) ? null : $translation->getText(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function addTranslation(Translation $translation) |
79
|
|
|
{ |
80
|
|
|
$translation->setTranslationId($this->getId()); |
81
|
|
|
$this->translations->add($translation); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function getTranslations() |
85
|
|
|
{ |
86
|
|
|
return $this->translations; |
87
|
|
|
} |
88
|
|
|
|
89
|
3 |
|
public function setTranslations($translations) |
90
|
|
|
{ |
91
|
3 |
|
foreach ($translations as $translation) { |
92
|
3 |
|
$translation->setTranslationId($this->getId()); |
93
|
|
|
} |
94
|
3 |
|
$this->translations = $translations; |
95
|
3 |
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param mixed $id |
99
|
|
|
*/ |
100
|
3 |
|
public function setId($id) |
101
|
|
|
{ |
102
|
3 |
|
$this->id = $id; |
103
|
3 |
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return mixed |
107
|
|
|
*/ |
108
|
3 |
|
public function getId() |
109
|
|
|
{ |
110
|
3 |
|
return $this->id; |
111
|
|
|
} |
112
|
|
|
|
113
|
3 |
|
public function getKeyword() |
114
|
|
|
{ |
115
|
3 |
|
return $this->keyword; |
116
|
|
|
} |
117
|
|
|
|
118
|
3 |
|
public function setKeyword($keyword) |
119
|
|
|
{ |
120
|
3 |
|
$this->keyword = $keyword; |
121
|
3 |
|
} |
122
|
|
|
|
123
|
3 |
|
public function getDomain() |
124
|
|
|
{ |
125
|
3 |
|
return $this->domain; |
126
|
|
|
} |
127
|
|
|
|
128
|
3 |
|
public function setDomain($domain) |
129
|
|
|
{ |
130
|
3 |
|
$this->domain = $domain; |
131
|
3 |
|
} |
132
|
|
|
} |
133
|
|
|
|
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..