Skip to content

Commit cea017b

Browse files
committed
#282 Minor updates to the Translations class
1 parent 1830ea4 commit cea017b

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/Translations.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,7 @@ public function addOrMerge(Translation $translation, int $mergeStrategy = 0): Tr
125125

126126
public function remove(Translation $translation): self
127127
{
128-
$key = array_search($translation, $this->translations);
129-
130-
if ($key !== false) {
131-
unset($this->translations[$key]);
132-
}
128+
unset($this->translations[$translation->getId()]);
133129

134130
return $this;
135131
}
@@ -168,13 +164,12 @@ public function getLanguage(): ?string
168164

169165
public function find(?string $context, string $original): ?Translation
170166
{
171-
foreach ($this->translations as $translation) {
172-
if ($translation->getContext() === $context && $translation->getOriginal() === $original) {
173-
return $translation;
174-
}
175-
}
167+
return $this->translations[(Translation::create($context, $original))->getId()] ?? null;
168+
}
176169

177-
return null;
170+
public function has(Translation $translation): bool
171+
{
172+
return (bool) ($this->translations[$translation->getId()] ?? false);
178173
}
179174

180175
public function mergeWith(Translations $translations, int $strategy = 0): Translations

0 commit comments

Comments
 (0)