1 | <?php |
||
13 | class Importer |
||
14 | { |
||
15 | /** |
||
16 | * @var array |
||
17 | */ |
||
18 | private $loaders = []; |
||
19 | |||
20 | /** |
||
21 | * @var TranslationGroupManager |
||
22 | */ |
||
23 | private $translationGroupManager; |
||
24 | |||
25 | 7 | public function __construct(TranslationGroupManager $translationGroupManager) |
|
29 | |||
30 | 3 | public function import(\Symfony\Component\Finder\SplFileInfo $file, $force = false) |
|
59 | |||
60 | /** |
||
61 | * @param string $file |
||
62 | * @param array $locales |
||
63 | * @param bool $force |
||
64 | * |
||
65 | * @return int |
||
66 | * |
||
67 | * @throws \Box\Spout\Common\Exception\IOException |
||
68 | * @throws \Box\Spout\Common\Exception\UnsupportedTypeException |
||
69 | * @throws \Box\Spout\Reader\Exception\ReaderNotOpenedException |
||
70 | */ |
||
71 | public function importFromSpreadsheet(string $file, array $locales, $force = false) |
||
135 | |||
136 | /** |
||
137 | * @param $keyword |
||
138 | * @param $text |
||
139 | * @param $locale |
||
140 | * @param $filename |
||
141 | * @param $domain |
||
142 | * @param bool $force |
||
143 | * |
||
144 | * @return bool |
||
145 | */ |
||
146 | 3 | private function importSingleTranslation($keyword, $text, $locale, $filename, $domain, $force = false) |
|
147 | { |
||
148 | 3 | if (strlen($keyword) > 255) { |
|
149 | return false; |
||
150 | } |
||
151 | |||
152 | 3 | $translationGroup = $this->translationGroupManager->getTranslationGroupByKeywordAndDomain($keyword, $domain); |
|
153 | |||
154 | 3 | if (!$translationGroup->hasTranslation($locale)) { |
|
155 | 3 | $this->translationGroupManager->addTranslation($translationGroup, $locale, $text, $filename); |
|
156 | |||
157 | 3 | return true; |
|
158 | } |
||
159 | |||
160 | 3 | if (true === $force) { |
|
161 | 1 | $this->translationGroupManager->updateTranslation($translationGroup, $locale, $text, $filename); |
|
162 | |||
163 | 1 | return true; |
|
164 | } |
||
165 | |||
166 | 2 | return false; |
|
167 | } |
||
168 | |||
169 | /** |
||
170 | * Adds a loader to the translation importer. |
||
171 | * |
||
172 | * @param string $format The format of the loader |
||
173 | * @param LoaderInterface $loader |
||
174 | */ |
||
175 | 7 | public function addLoader($format, LoaderInterface $loader) |
|
179 | } |
||
180 |