24 private $convertEncoding;
36 private $tmpFolderPath;
39 private $targetFolderPath;
42 private $sourceFolderPath;
45 private $totalFileCount;
60 private $seekAncestors;
73 'languageId',
'convertEncoding',
'encoding',
'encodingIn',
'encodingOut',
74 'tmpFolderPath',
'totalFileCount',
'sourceFolderPath',
'targetFolderPath',
'seekPath'
84 if (self::$useTranslationRepository)
100 $this->languageId = $progressParams[
'languageId'];
101 $this->tmpFolderPath = $progressParams[
'tmpFolderPath'];
102 $this->totalFileCount = $progressParams[
'totalFileCount'];
105 if ($this->isNewProcess)
107 $this->totalItems = $this->totalFileCount;
108 $this->processedItems = 0;
111 $languageId = $this->controller->getRequest()->get(
'languageId');
112 if (empty($languageId))
116 if (!in_array($languageId, self::$enabledLanguages))
122 $this->languageId = $languageId;
126 $this->convertEncoding = ($this->controller->getRequest()->
get(
'localizeEncoding') ===
'Y');
129 $encoding = $this->controller->getRequest()->get(
'encoding');
130 if ($encoding !==
null && \in_array($encoding, self::$allowedEncodings))
132 $this->encoding = $encoding;
134 elseif ($this->convertEncoding)
139 if ($this->convertEncoding)
141 if (self::$useTranslationRepository)
143 $encodingIn = $this->encoding;
148 $encodingIn = $this->encoding;
149 $encodingOut =
'utf-8';
153 $encodingIn =
'utf-8';
160 $this->convertEncoding = (\mb_strtolower($encodingIn) !== \mb_strtolower($encodingOut));
161 $this->encodingIn = $encodingIn;
162 $this->encodingOut = $encodingOut;
168 if (!$sourceDirectory->isExists())
171 new Error(Loc::getMessage(
'TR_ERROR_CREATE_TARGET_FOLDER', [
'#PATH#' => $this->sourceFolderPath]))
176 self::$useTranslationRepository &&
180 $this->targetFolderPath =
Translate\IO\Path::tidy(self::$translationRepositoryRoot.
'/'. $this->languageId.
'/');
182 if (!$targetFolder->isExists())
184 $targetFolder->create();
196 'PROCESSED_ITEMS' => 0,
197 'TOTAL_ITEMS' => $this->totalItems,
201 $this->targetFolderPath = $progressParams[
'targetFolderPath'];
202 $this->convertEncoding = $progressParams[
'convertEncoding'];
203 $this->encodingIn = $progressParams[
'encodingIn'];
204 $this->encodingOut = $progressParams[
'encodingOut'];
205 $this->seekPath = $progressParams[
'seekPath'];
216 private function runApplying():
array
218 $processedItemCount = 0;
220 if (!empty($this->seekPath))
222 $this->seekAncestors = [];
223 $arr = \explode(
'/', \str_replace($this->sourceFolderPath,
'', $this->seekPath));
226 foreach (
$arr as $part)
229 $this->seekAncestors[] = $this->sourceFolderPath. \implode(
'/', $parts);
233 foreach ($this->lookThroughTmpFolder($this->sourceFolderPath) as $filePaths)
235 foreach ($filePaths as $langFilePath => $fullPath)
237 $targetFolder =
new Main\IO\Directory($this->targetFolderPath. \dirname($langFilePath));
238 if (!$targetFolder->isExists())
240 $targetFolder->create();
244 $target =
new Main\IO\File($targetFolder->getPhysicalPath().
'/'. \basename($langFilePath));
245 if ($target->isExists())
247 $target->markWritable();
252 if ($this->convertEncoding)
257 $content = Main\Text\Encoding::convertEncoding(
$content, $this->encodingIn, $this->encodingOut);
262 if (\function_exists(
'error_clear_last'))
266 if (\copy($source->getPhysicalPath(), $target->getPhysicalPath()) !==
true)
268 $error = \error_get_last();
274 $processedItemCount ++;
276 catch (Main\IO\IoException $exception)
282 if (\connection_status() !== \CONNECTION_NORMAL)
284 throw new Main\SystemException(
'Process has been broken course user aborted connection.');
290 $this->seekPath = $fullPath;
295 $this->processedItems += $processedItemCount;
306 $updatePublic = $this->controller->getRequest()->get(
'updatePublic');
307 if ($updatePublic ===
'Y')
310 $this->processToken =
null;
317 $result[
'SUMMARY'] = Loc::getMessage(
'TR_LANGUAGE_DOWNLOADED');
331 private function lookThroughTmpFolder($tmpFolderFullPath): iterable
336 $tmpFolderFullPath = Translate\IO\Path::tidy(\rtrim($tmpFolderFullPath,
'/'));
337 $langFolderRelPath = \str_replace($this->sourceFolderPath,
'', $tmpFolderFullPath);
339 $childrenList = Translate\IO\FileSystemHelper::getFileList($tmpFolderFullPath);
340 if (!empty($childrenList))
342 foreach ($childrenList as $fullPath)
344 if (!empty($this->seekPath))
346 if ($this->seekPath != $fullPath)
351 $this->seekPath =
null;
352 $this->seekAncestors =
null;
355 $name = \basename($fullPath);
361 if (Translate\IO\Path::isPhpFile($fullPath,
true))
369 $childrenList = Translate\IO\FileSystemHelper::getFolderList($tmpFolderFullPath);
370 if (!empty($childrenList))
372 foreach ($childrenList as $fullPath)
374 $name = \basename($fullPath);
380 if (!empty($this->seekPath))
382 if (\in_array($fullPath, $this->seekAncestors))
384 foreach ($this->lookThroughTmpFolder($fullPath) as $subFiles)
392 if (!\is_dir($fullPath))
413 if (\
count($folders) > 0)
415 foreach ($folders as $subFolderPath)
417 foreach ($this->lookThroughTmpFolder($subFolderPath) as $subFiles)
434 return $controller::SETTING_ID;
static getSourceEncoding($lang)
static useTranslationRepository()
static getCurrentEncoding()
static getTranslationRepositoryPath()
static isDefaultTranslationLang($lang)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)