Conditions | 9 |
Paths | 72 |
Total Lines | 39 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
21 | public function loadArray(array $array, Translations $translations = null): Translations |
||
22 | { |
||
23 | if (!$translations) { |
||
24 | $translations = $this->createTranslations(); |
||
25 | } |
||
26 | |||
27 | $messages = $array['messages'] ?? []; |
||
28 | |||
29 | foreach ($messages as $context => $contextTranslations) { |
||
30 | if ($context === '') { |
||
31 | $context = null; |
||
32 | } |
||
33 | |||
34 | foreach ($contextTranslations as $original => $value) { |
||
35 | if ($original === '') { |
||
36 | continue; |
||
37 | } |
||
38 | |||
39 | $translation = $this->createTranslation($context, $original); |
||
40 | $translations->add($translation); |
||
41 | |||
42 | if (is_array($value)) { |
||
43 | $translation->translate(array_shift($value)); |
||
44 | $translation->translatePlural(...$value); |
||
45 | } else { |
||
46 | $translation->translate($value); |
||
47 | } |
||
48 | } |
||
49 | } |
||
50 | |||
51 | if (!empty($array['domain'])) { |
||
52 | $translations->setDomain($array['domain']); |
||
53 | } |
||
54 | |||
55 | if (!empty($array['plural-forms'])) { |
||
56 | $translations->getHeaders()->set(Headers::HEADER_PLURAL, $array['plural-forms']); |
||
57 | } |
||
58 | |||
59 | return $translations; |
||
60 | } |
||
62 |