• Модуль: translate
  • Путь к файлу: ~/bitrix/modules/translate/lib/controller/editor/cleanethalon.php
  • Класс: BitrixTranslateControllerEditorCleanEthalon
  • Вызов: CleanEthalon::cleanLangFile
private function cleanLangFile($relLangPath): void
{
	$currentLang = Loc::getCurrentLang();
	$langPath = TranslateIOPath::replaceLangId($relLangPath, $currentLang);
	$langFullPath = TranslateIOPath::tidy(self::$documentRoot. '/'. $langPath);
	$langFullPath = MainLocalizationTranslation::convertLangPath($langFullPath, $currentLang);

	try
	{
		$ethalonFile = TranslateFile::instantiateByPath($langFullPath);
	}
	catch (MainArgumentException $ex)
	{
		return;
	}
	if ($ethalonFile instanceof TranslateFile)
	{
		$ethalonFile
			->setLangId($currentLang)
			->setOperatingEncoding(MainLocalizationTranslation::getSourceEncoding($currentLang));

		$isEthalonExists = false;
		if ($ethalonFile->isExists())
		{
			$isEthalonExists = $ethalonFile->loadTokens() || $ethalonFile->load();
		}
		if (!$isEthalonExists)
		{
			$this->deletePhraseIndex($ethalonFile);
		}

		foreach (self::$enabledLanguagesList as $langId)
		{
			if ($langId == $currentLang)
			{
				continue;
			}

			$langPath = TranslateIOPath::replaceLangId($relLangPath, $langId);
			$langFullPath = TranslateIOPath::tidy(self::$documentRoot.'/'.$langPath);
			$langFullPath = MainLocalizationTranslation::convertLangPath($langFullPath, $langId);

			try
			{
				$langFile = TranslateFile::instantiateByPath($langFullPath);
			}
			catch (MainArgumentException $ex)
			{
				continue;
			}
			if ($langFile instanceof TranslateFile)
			{
				$langFile
					->setLangId($langId)
					->setOperatingEncoding(MainLocalizationTranslation::getSourceEncoding($langId));

				if ($langFile->isExists())
				{
					if ($isEthalonExists && ($langFile->loadTokens() || $langFile->load()))
					{
						$affected = false;
						foreach ($langFile as $code => $phrase)
						{
							if (!isset($ethalonFile[$code]))
							{
								unset($langFile[$code]);
								$affected = true;
							}
						}
						if ($affected)
						{
							$this->updateLangFile($langFile);
							$this->updatePhraseIndex($langFile);
						}
					}
					else
					{
						$this->deletePhraseIndex($langFile);
						$this->deleteLangFile($langFile);
					}
				}
				else
				{
					$langFile->deletePhraseIndex();
				}
			}
		}
	}
}