21 public function run($file =
'')
32 $normalized = Main\IO\Path::normalize($file);
33 if ($normalized != $file)
39 if (!Translate\
IO\Path::isLangDir($file,
true) || !Translate\
IO\Path::isPhpFile($file))
50 $request = $this->controller->getRequest();
52 $phraseIdsToDrop = $languagesToDrop = $phraseIdsToUpdate = $languagesToUpdate = [];
56 $currentEncoding = Main\Localization\Translation::getCurrentEncoding();
58 $limitEncoding = !($currentEncoding ===
'utf-8' || Main\Localization\Translation::useTranslationRepository());
60 $isEncodingCompatible =
function ($langId) use ($limitEncoding, $currentEncoding, $currentLang)
66 $langId == $currentLang ||
67 Translate\Config::getCultureEncoding($langId) == $currentEncoding ||
76 $phraseIdsToDropTmp = $request->getPost(
'DROP');
77 if ($phraseIdsToDropTmp !==
null && \is_array($phraseIdsToDropTmp) && \count($phraseIdsToDropTmp) > 0)
79 $phraseIdsToDrop = $phraseIdsToDropTmp;
82 unset($phraseIdsToDropTmp);
85 $phraseIdsToUpdateTmp = $request->getPost(
'KEYS');
86 if ($phraseIdsToUpdateTmp !==
null && \is_array($phraseIdsToUpdateTmp) && \count($phraseIdsToUpdateTmp) > 0)
88 $phraseIdsToUpdate = $phraseIdsToUpdateTmp;
90 unset($phraseIdsToUpdateTmp);
93 $languagesToUpdateTmp = $request->getPost(
'LANGS');
94 if ($languagesToUpdateTmp !==
null && \is_array($languagesToUpdateTmp) && \count($languagesToUpdateTmp) > 0)
98 unset($languagesToUpdateTmp);
101 if (empty($phraseIdsToUpdate) && empty($phraseIdsToDrop))
106 if (!empty($phraseIdsToUpdate) && empty($languagesToUpdate))
114 $result[
'DROPPED'] = [];
115 $result[
'UPDATED'] = [];
116 $result[
'CLEANED'] = [];
120 if (!\in_array($langId, $languagesToUpdate) && !\in_array($langId, $languagesToDrop))
125 $langRelPath = Translate\IO\Path::replaceLangId($file, $langId);
126 $fullPath = Translate\IO\Path::tidy(
$documentRoot.
'/'. $langRelPath);
127 $fullPath = Main\Localization\Translation::convertLangPath($fullPath, $langId);
130 $langFile->setLangId($langId);
134 if (\in_array($langId, $languagesToUpdate))
136 $langFile->setOperatingEncoding($currentEncoding);
139 elseif (\in_array($langId, $languagesToDrop))
144 if (!$langFile->loadTokens())
146 if (!$langFile->load() && $langFile->hasErrors())
148 foreach ($langFile->getErrors() as $error)
150 if ($error->getCode() !==
'EMPTY_CONTENT')
162 $hasDataToUpdate =
false;
165 if (\in_array($langId, $languagesToDrop))
167 foreach ($phraseIdsToDrop as $phraseId)
169 if (isset($langFile[$phraseId]))
171 unset($langFile[$phraseId]);
173 $hasDataToUpdate =
true;
174 if (!\in_array($phraseId, $result[
'DROPPED']))
176 $result[
'DROPPED'][] = $phraseId;
183 if (\in_array($langId, $languagesToUpdate) && $isEncodingCompatible($langId))
185 foreach ($phraseIdsToUpdate as $phraseId)
188 if (\in_array($phraseId, $phraseIdsToDrop))
193 $fldName = $this->generateFieldName($phraseId, $langId);
194 if (!isset($request[$fldName]))
198 $inpValue = $request->getPost($fldName);
201 if (!empty($inpValue) || $inpValue ===
'0')
203 if ($langFile[$phraseId] !== $inpValue)
205 $langFile[$phraseId] = $inpValue;
207 $hasDataToUpdate =
true;
208 if (!\in_array($fldName, $result[
'UPDATED']))
210 $result[
'UPDATED'][] = $fldName;
215 elseif (isset($langFile[$phraseId]) && $inpValue ===
'')
217 unset($langFile[$phraseId]);
219 $hasDataToUpdate =
true;
220 if (!\in_array($fldName, $result[
'CLEANED']))
222 $result[
'CLEANED'][] = $fldName;
228 if ($hasDataToUpdate)
230 if ($langFile->count() > 0)
234 $langFile->updatePhraseIndex();
239 if ($langFile->isExists())
241 $langFile->deletePhraseIndex();
244 $langFile->removeEmptyParents();
268 private function generateFieldName($phraseId, $suffix =
'', $prefix =
'')
271 (!empty($prefix) ? $prefix.
'_' :
'').
272 \str_replace([
'.',
'-',
' '],
'_', $phraseId).
273 (!empty($suffix) ?
'_'.$suffix :
'')
static loadLanguageFile($file, $language=null, $normalize=true)
static getMessage($code, $replace=null, $language=null)