16 use Translate\Controller\Stepper;
17 use Translate\Controller\ProcessParams;
28 private $seekLangPath;
40 $this->
keepField([
'pathList',
'seekOffset',
'seekLangPath']);
53 public function run($pathList)
55 if ($this->isNewProcess)
57 $pathList = \preg_split(
"/[\r\n]+/", $pathList);
58 \array_walk($pathList,
'trim');
59 $pathList = \array_unique(\array_filter($pathList));
66 'STATUS' => Translate\Controller\STATUS_COMPLETED,
70 foreach ($pathList as $testPath)
72 if (Translate\
IO\Path::isPhpFile($testPath))
74 if (Translate\
IO\Path::isLangDir($testPath))
76 $this->pathList[] = $testPath;
85 if (Translate\
IO\Path::isLangDir($testPath))
87 $this->pathList[] = $testPath;
95 '=PATH' => \rtrim($testPath,
'/'),
96 '=%PATH' => \rtrim($testPath,
'/').
'/%'
98 $pathLangRes = Index\Internals\PathLangTable::getList([
99 'filter' => $pathFilter,
100 'order' => [
'ID' =>
'ASC'],
101 'select' => [
'PATH'],
103 while ($pathLang = $pathLangRes->fetch())
105 $this->pathList[] = $pathLang[
'PATH'];
111 $this->totalItems = \count($this->pathList);
112 $this->processedItems = 0;
114 if ($this->totalItems == 0)
117 'STATUS' => Translate\Controller\STATUS_COMPLETED,
118 'PROCESSED_ITEMS' => 0,
124 $this->isNewProcess =
false;
135 private function runClearing(): array
137 $processedItemCount = 0;
138 for ($pos = ((
int)$this->seekOffset > 0 ? (
int)$this->seekOffset : 0), $total = \count($this->pathList); $pos < $total; $pos ++)
140 $testPath = $this->pathList[$pos];
143 if (Translate\
IO\Path::isPhpFile($testPath))
145 $this->cleanLangFile($testPath);
151 if (\mb_substr($testPath, -5) ===
'/lang')
153 $testPath .=
'/#LANG_ID#';
157 $testPath = Translate\IO\Path::replaceLangId($testPath,
'#LANG_ID#');
162 foreach ($filePaths as $langFilePath => $fullPaths)
164 if (!empty($this->seekLangPath))
166 if ($this->seekLangPath == $langFilePath)
168 $this->seekLangPath =
null;
174 $this->cleanLangFile($langFilePath);
178 $this->seekLangPath = $langFilePath;
183 $this->seekLangPath =
null;
187 $processedItemCount ++;
189 if (isset($this->pathList[$pos + 1]))
191 $this->seekOffset = $pos + 1;
195 $this->seekOffset =
null;
206 $this->processedItems += $processedItemCount;
228 private function cleanLangFile($relLangPath): void
231 $langPath = Translate\IO\Path::replaceLangId($relLangPath, $currentLang);
232 $langFullPath = Translate\IO\Path::tidy(self::$documentRoot.
'/'. $langPath);
233 $langFullPath = Main\Localization\Translation::convertLangPath($langFullPath, $currentLang);
237 $ethalonFile = Translate\File::instantiateByPath($langFullPath);
239 catch (Main\ArgumentException $ex)
243 if ($ethalonFile instanceof Translate\File)
246 ->setLangId($currentLang)
249 $isEthalonExists =
false;
250 if ($ethalonFile->isExists())
252 $isEthalonExists = $ethalonFile->loadTokens() || $ethalonFile->load();
254 if (!$isEthalonExists)
259 foreach (self::$enabledLanguagesList as $langId)
261 if ($langId == $currentLang)
266 $langPath = Translate\IO\Path::replaceLangId($relLangPath, $langId);
267 $langFullPath = Translate\IO\Path::tidy(self::$documentRoot.
'/'.$langPath);
268 $langFullPath = Main\Localization\Translation::convertLangPath($langFullPath, $langId);
272 $langFile = Translate\File::instantiateByPath($langFullPath);
274 catch (Main\ArgumentException $ex)
278 if ($langFile instanceof Translate\File)
284 if ($langFile->isExists())
286 if ($isEthalonExists && ($langFile->loadTokens() || $langFile->load()))
289 foreach ($langFile as $code => $phrase)
291 if (!isset($ethalonFile[$code]))
293 unset($langFile[$code]);
311 $langFile->deletePhraseIndex();
static getMessage($code, $replace=null, $language=null)
static getSourceEncoding($lang)