1 | <?php |
||
17 | class Localization implements LocalizationInterface |
||
18 | { |
||
19 | /** |
||
20 | * Language of the localization |
||
21 | */ |
||
22 | protected string $language; |
||
|
|||
23 | |||
24 | /** |
||
25 | * Localized images |
||
26 | * |
||
27 | * @var ImageInterface[] |
||
28 | */ |
||
29 | protected array $images = []; |
||
30 | |||
31 | /** |
||
32 | * Localized texts (token=>value) |
||
33 | * |
||
34 | * @var string[] |
||
35 | */ |
||
36 | protected array $strings = []; |
||
37 | |||
38 | public function __construct($language) |
||
39 | { |
||
40 | $this->setLanguage($language); |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * {@inheritdoc} |
||
45 | */ |
||
46 | public function setLanguage($language): void |
||
47 | { |
||
48 | $this->language = $language; |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * {@inheritdoc} |
||
53 | */ |
||
54 | public function getLanguage() |
||
55 | { |
||
56 | return $this->language; |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * {@inheritdoc} |
||
61 | */ |
||
62 | public function addString($token, $value) |
||
63 | { |
||
64 | $this->strings[$token] = $value; |
||
65 | |||
66 | return $this; |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * {@inheritdoc} |
||
71 | */ |
||
72 | public function addStrings(array $strings) |
||
73 | { |
||
74 | $this->strings = array_merge($this->strings, $strings); |
||
75 | |||
76 | return $this; |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * {@inheritdoc} |
||
81 | */ |
||
82 | public function getStrings() |
||
83 | { |
||
84 | return $this->strings; |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * {@inheritdoc} |
||
89 | */ |
||
90 | public function getStringsFileOutput() |
||
91 | { |
||
92 | $output = ''; |
||
93 | foreach ($this->strings as $token => $value) { |
||
94 | $output .= '"' . addslashes($token) . '" = "' . addslashes($value) . '";' . PHP_EOL; |
||
95 | } |
||
96 | |||
97 | return $output; |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * {@inheritdoc} |
||
102 | */ |
||
103 | public function addImage(Image $image) |
||
104 | { |
||
105 | $this->images[] = $image; |
||
106 | |||
107 | return $this; |
||
108 | } |
||
109 | |||
110 | /** |
||
111 | * {@inheritdoc} |
||
112 | */ |
||
113 | public function getImages() |
||
114 | { |
||
115 | return $this->images; |
||
116 | } |
||
117 | } |
||
118 |