17 use Translate\Controller\Stepper;
18 use Translate\Controller\ProcessParams;
41 private $languageList;
56 $fields = [
'tabId',
'csvFilePath',
'seekLine',
'seekPath'];
60 foreach ($fields as $key)
70 self::$enabledLanguages = Translate\Config::getEnabledLanguages();
82 public function run($runBefore =
false)
92 ->setFieldsType(Translate\
IO\CsvFile::FIELDS_TYPE_WITH_DELIMITER)
93 ->setFirstHeader(
false)
96 if (!$this->csvFile->openLoad())
101 'STATUS' => Translate\Controller\STATUS_COMPLETED
104 if (!$this->verifyCsvFile())
108 'STATUS' => Translate\Controller\STATUS_COMPLETED
112 if ($this->isNewProcess)
116 $this->totalItems = 0;
118 $fileColumn = $this->columnList[
'file'];
119 while ($csvRow = $this->csvFile->fetch())
121 $filePath = (isset($csvRow[$fileColumn]) ? $csvRow[$fileColumn] :
'');
126 if (isset($uniquePaths[$filePath]))
130 $uniquePaths[$filePath] = 1;
131 $this->totalItems ++;
133 $this->csvFile->moveFirst();
135 $this->processedItems = 0;
140 $this->isNewProcess =
false;
146 if (isset($progressParams[
'totalItems']))
148 $this->totalItems = $progressParams[
'totalItems'];
150 if (isset($progressParams[
'seekLine']))
152 $this->seekLine = $progressParams[
'seekLine'];
154 if (isset($progressParams[
'seekPath']))
156 $this->seekPath = $progressParams[
'seekPath'];
168 private function runIndexing(): array
170 $fileColumn = $this->columnList[
'file'];
174 if (!empty($this->seekPath))
176 $uniquePaths[$this->seekPath] = 1;
182 while ($csvRow = $this->csvFile->fetch())
186 if ($this->seekLine > 0)
188 if ($currentLine <= $this->seekLine)
195 !\is_array($csvRow) ||
197 (\count($csvRow) == 1 && ($csvRow[0] ===
null || $csvRow[0] ===
''))
203 $filePath = (isset($csvRow[$fileColumn]) ? $csvRow[$fileColumn] :
'');
208 if (Translate\
IO\Path::isLangDir($filePath,
true) !==
true)
212 $filePath = Translate\IO\Path::normalize(
'/'.$filePath);
214 if (isset($uniquePaths[$filePath]))
219 foreach ($this->languageList as $languageId)
221 $langFilePath = Translate\IO\Path::replaceLangId($filePath, $languageId);
223 $fullPath = self::$documentRoot. $langFilePath;
224 $fullPath = Main\Localization\Translation::convertLangPath($fullPath, $languageId);
226 $langFile =
new Translate\File($fullPath);
227 $langFile->setLangId($languageId);
229 if (!$langFile->load())
231 $this->
addErrors($langFile->getErrors());
235 if ($langFile->getFileIndex()->getId() <= 0)
237 $topPath = $pathIndexer->constructAncestorsByPath($filePath);
239 if ($topPath[
'ID'] > 0)
241 $fileIndex = $langFile->getFileIndex();
242 $fileIndex->setPathId($topPath[
'ID']);
246 $langFile->updatePhraseIndex();
249 $uniquePaths[$filePath] = 1;
250 $this->processedItems ++;
254 $this->seekLine = $currentLine;
255 $this->seekPath = $filePath;
260 $this->csvFile->close();
280 private function verifyCsvFile(): bool
283 Translate\IO\CsvFile::DELIMITER_TZP,
284 Translate\IO\CsvFile::DELIMITER_TAB,
285 Translate\IO\CsvFile::DELIMITER_ZPT,
287 foreach ($testDelimiters as $delimiter)
289 $this->csvFile->setFieldDelimiter($delimiter);
291 $this->csvFile->moveFirst();
292 $rowHead = $this->csvFile->fetch();
294 !\is_array($rowHead) ||
296 empty($rowHead[0]) ||
297 (\count($rowHead) < 3)
307 !\is_array($rowHead) ||
309 empty($rowHead[0]) ||
310 (\count($rowHead) < 3)
317 $this->columnList = \array_flip($rowHead);
318 foreach ($this->languageList as $keyLang => $langID)
320 if (!isset($this->columnList[$langID]))
322 unset($this->languageList[$keyLang]);
325 if (!isset($this->columnList[
'file']))
static getMessage($code, $replace=null, $language=null)