31 if ($showTranslationDifferences)
69 if (preg_match(
'|^' . preg_quote(realpath(
Main\Application::getDocumentRoot() .
'/upload'),
'|') .
'|iu', $fullPath))
81 in_array($langId,
Translate\Config::getTranslationRepositoryLanguages())
88 $fullPath = realpath($fullPath);
93 $fullPath = realpath($fullPath);
106 while (
false !== ($file = readdir(
$handle)))
113 $isDir = is_dir($absParent. $file);
114 $pathPrepared = $parent. $file;
120 if (!$isDir && (mb_substr($file, -4) !==
'.php'))
125 $arList[$pathPrepared] =
array(
126 'IS_DIR' => ($isDir ?
'Y' :
'N'),
128 'PATH' => ($isDir ? $pathPrepared.
"/" : $pathPrepared),
130 'IS_LANG' => $isLang,
131 'FULL_PATH' => $absParent. $file,
140 foreach (
Translate\Config::getTranslationRepositoryLanguages() as $langId)
142 if (!empty($restructLanguageList) && !in_array($langId, $restructLanguageList))
147 $langPathPrepared = $langParent . $arList[$pathPrepared][
'FILE'];
151 if (file_exists($langPath))
153 $arList[$langPath] =
array(
155 'PARENT' => $langParent,
156 'PATH' => $langPathPrepared,
157 'FILE' => $arList[$pathPrepared][
'FILE'],
158 'FULL_PATH' => $langPath,
160 'IS_LANG_REP' =>
true,
171 foreach($arList as $pathPrepared =>
$arr)
173 if(
$arr[
'IS_DIR'] ==
'Y')
177 $arr[
'IS_LANG'] |=
GetTDirList($pathPrepared.
'/', $subDirs, $restructLanguageList);
182 $isLang = $isLang ||
$arr[
'IS_LANG'];
186 if(mb_substr(
$arr[
'FILE'], -4) ==
'.php')
210function GetTCSVArray($filterKeyIndex, $targetEncoding =
'', $restructLanguageList =
array())
224 if (
$key != $filterKeyIndex)
229 if (isset($file[
'LANG']))
231 $langId = $file[
'LANG'];
238 if (!empty($restructLanguageList) && !in_array($langId, $restructLanguageList))
243 if (isset($file[
'FULL_PATH']))
245 $fname = $file[
'FULL_PATH'];
261 foreach (
$MESS as $phraseCode => $phrase)
263 $phraseCode = (string)$phraseCode;
264 if ($phraseCode !=
'')
266 if ($targetEncoding !=
'' && $sourceEncoding != $targetEncoding)
269 $phrase = Encoding::convertEncoding($phrase, $sourceEncoding, $targetEncoding,
$errorMessage);
277 $arr[
$key][$phraseCode][$langId] = $phrase;
302 $phraseList =
array();
307 $csvFile =
new Translate\IO\CsvFile($filePath);
308 if (!$csvFile->openLoad())
310 $errors[] = Loc::getMessage(
'TR_TOOLS_ERROR_EMPTY_FILE');
314 if ($csvFile->hasUtf8Bom())
316 $encodingIn =
'utf-8';
320 ->setFieldsType(
Translate\
IO\CsvFile::FIELDS_TYPE_WITH_DELIMITER)
321 ->setFirstHeader(
false)
322 ->setFieldDelimiter(
Translate\
IO\CsvFile::DELIMITER_TZP);
324 $rowHead = $csvFile->fetch();
326 !is_array($rowHead) ||
328 (
count($rowHead) == 1 && ($rowHead[0] ===
null || $rowHead[0] ===
''))
331 $errors[] = Loc::getMessage(
'BX_TRANSLATE_IMPORT_ERR_EMPTY_FIRST_ROW');
336 foreach ($languageList as $keyLang => $langID)
340 unset($languageList[$keyLang]);
345 $errors[] = Loc::getMessage(
'BX_TRANSLATE_IMPORT_ERR_DESTINATION_FIELD_ABSENT');
353 $errors[] = Loc::getMessage(
'BX_TRANSLATE_IMPORT_ERR_PHRASE_CODE_FIELD_ABSENT');
359 if (empty($languageList))
361 $errors[] = Loc::getMessage(
'BX_TRANSLATE_IMPORT_ERR_LANGUAGE_LIST_ABSENT');
368 while ($csvRow = $csvFile->fetch())
372 !is_array($csvRow) ||
374 (
count($csvRow) == 1 && ($csvRow[0] ===
null || $csvRow[0] ===
''))
379 $file = (isset($csvRow[$fileIndex]) ? $csvRow[$fileIndex] :
'');
380 $key = (isset($csvRow[$keyIndex]) ? $csvRow[$keyIndex] :
'');
381 if ($file ==
'' ||
$key ==
'')
386 $rowErrors[] = Loc::getMessage(
'BX_TRANSLATE_IMPORT_ERR_DESTINATION_FILEPATH_ABSENT');
390 $rowErrors[] = Loc::getMessage(
'BX_TRANSLATE_IMPORT_ERR_PHRASE_CODE_ABSENT');
393 'TR_TOOLS_ERROR_LINE_FILE_EXT',
394 [
'#LINE#' => $csvRowCounter,
'#ERROR#' => implode(
'; ', $rowErrors)]
404 if (!isset($phraseList[$file]))
406 $phraseList[$file] = [];
408 foreach ($languageList as $languageId)
410 if (!isset($phraseList[$file][$languageId]))
412 $phraseList[$file][$languageId] = [];
416 if (!isset($csvRow[$langIndex]))
418 $rowErrors[] = Loc::getMessage(
419 'BX_TRANSLATE_IMPORT_ERR_ROW_LANG_ABSENT',
420 [
'#LANG#' => $languageId]
424 if ($csvRow[$langIndex] ===
'')
429 $phrase = str_replace(
"\\\\",
"\\", $csvRow[$langIndex]);
431 if ($useTranslationRepository)
437 $encodingOut =
'utf-8';
449 $encodingIn !==
'' &&
450 $encodingOut !==
'' &&
451 $encodingIn !== $encodingOut
455 $phrase = Encoding::convertEncoding($phrase, $encodingIn, $encodingOut,
$errorMessage);
465 if ($encodingOut ==
'utf-8')
467 $validPhrase = preg_replace(
"/[^\x01-\x7F]/",
'', $phrase);
468 if ($validPhrase !== $phrase)
477 $phraseList[$file][$languageId][
$key] = $phrase;
481 $rowErrors[] = Loc::getMessage(
482 'BX_TRANSLATE_IMPORT_ERR_NO_VALID_UTF8_PHRASE',
483 [
'#LANG#' => $languageId]
487 unset($checked, $phrase);
490 if (!empty($rowErrors))
493 'TR_TOOLS_ERROR_LINE_FILE_BIG',
495 '#LINE#' => $csvRowCounter,
496 '#FILENAME#' => $file,
498 '#ERROR#' => implode(
'; ', $rowErrors),
509 foreach ($phraseList as $fileIndex => $translationList)
511 if (
Translate\
IO\Path::isLangDir($fileIndex,
true) !==
true)
513 $errors[] = Loc::getMessage(
'TR_TOOLS_ERROR_FILE_NOT_LANG',
array(
'%FILE%' => $fileIndex));
516 foreach ($translationList as $languageId => $fileMessages)
518 if (empty($fileMessages))
524 $file =
Rel2Abs(
'/', $rawFile);
525 if ($file !== $rawFile)
528 'BX_TRANSLATE_IMPORT_ERR_BAD_FILEPATH',
529 [
'#FILE#' => $fileIndex]
538 if (in_array($languageId,
Translate\Config::getTranslationRepositoryLanguages()))
544 $fullPath = realpath($fullPath);
549 $fullPath = realpath($fullPath);
555 if (!$rewriteMode && file_exists($fullPath))
560 if (!is_array(
$MESS))
566 foreach (array_keys(
$MESS) as $index)
568 if (
$MESS[$index] ===
'')
570 unset(
$MESS[$index]);
607function GetTLangFiles(
$path, $IS_LANG_DIR =
false)
620 $path_l = mb_strlen(
$path);
626 if(
$arr[
"IS_DIR"]==
"N" && (strncmp(
$arr[
"PATH"],
$path, $path_l) == 0))
638 $path_l = mb_strlen(
$path);
642 if(
$arr[
"IS_DIR"]==
"N" && (strncmp(
$arr[
"PATH"],
$path, $path_l) == 0))
671 if (isset($arFile[
'LANG']))
673 $langId = $arFile[
'LANG'];
684 include $arFile[
'FULL_PATH'];
701 $_arSearchData =
array();
714 foreach (
$MESS as $_sMn => $_sMe)
716 if ($targetEncoding !=
'' && $sourceEncoding != $targetEncoding)
719 $_sMe = Encoding::convertEncoding($_sMe, $sourceEncoding, $targetEncoding,
$errorMessage);
726 $__sMe = mb_strtolower($_sMe);
727 $__sMn = mb_strtolower($_sMn);
734 if (mb_strpos($__sMe, $_phrase) !==
false)
739 if (mb_strpos($__sMn, $_phrase) !==
false)
750 $pattern =
'/'.preg_quote($phrase,
'/').
'/Su'.$I_PCRE_MODIFIER;
768 $pattern =
'/'.preg_quote($phrase,
'/').
'/u'.$I_PCRE_MODIFIER;
784 $_arSearchData[$_sMn] = $_sMe;
790 $errorCollection = [];
791 saveTranslationFile($arFile[
'PATH'], $_arSearchData, $errorCollection);
792 $_bResult = empty($errorCollection);
806 if (
Main\
Config\Option::get(
'translate',
'BACKUP_FILES',
'N') !==
'Y')
817 if (in_array($langId,
Translate\Config::getTranslationRepositoryLanguages()))
823 $fullPath = realpath($fullPath);
828 $fullPath = realpath($fullPath);
832 if (!file_exists($fullPath))
839 if (!file_exists($endpointBackupFolder) || !is_dir($endpointBackupFolder))
845 $prefix = date(
'YmdHi');
846 $endpointBackupFilename = $prefix.
'_'. $sourceFilename;
847 if (file_exists($endpointBackupFolder. $endpointBackupFilename))
850 while (file_exists($endpointBackupFolder.
'/'. $endpointBackupFilename))
853 $endpointBackupFilename = $prefix.
'_'.
$i.
'_'. $sourceFilename;
857 $isSuccessfull = (bool) @copy($fullPath, $endpointBackupFolder.
'/'. $endpointBackupFilename);
858 @chmod($endpointBackupFolder.
'/'. $endpointBackupFilename, BX_FILE_PERMISSIONS);
860 return $isSuccessfull;
887 public const LANGUAGES_DEFAULT = 0;
888 public const LANGUAGES_EXIST = 1;
889 public const LANGUAGES_ACTIVE = 2;
890 public const LANGUAGES_CUSTOM = 3;
892 protected static array $languageList = [
898 public static function setLanguageList(
int $languages = self::LANGUAGES_DEFAULT, $customList = [])
900 if ($languages == self::LANGUAGES_ACTIVE || $languages == self::LANGUAGES_EXIST)
902 self::$languageList = [];
903 if ($languages === self::LANGUAGES_ACTIVE)
905 $languageIterator = LanguageTable::getList([
916 $languageIterator = LanguageTable::getList([
922 while (
$lang = $languageIterator->fetch())
924 self::$languageList[] =
$lang[
'ID'];
926 unset(
$lang, $languageIterator);
928 elseif ($languages === self::LANGUAGES_CUSTOM)
930 if (!is_array($customList))
932 $customList = [$customList];
934 self::$languageList = $customList;
938 self::$languageList = [
947 public static function CopyMessage(
$code, $fileFrom, $fileTo, $newCode =
'')
949 $newCode = (string)$newCode;
953 $filePath = $fileFrom;
954 while(($slashPos = mb_strrpos($filePath,
"/")) !==
false)
956 $filePath = mb_substr($filePath, 0, $slashPos);
957 if(is_dir($filePath.
"/lang"))
959 $langDir = $filePath.
"/lang";
960 $fileName = mb_substr($fileFrom, $slashPos);
966 $langDirTo = $fileNameTo =
"";
968 while(($slashPos = mb_strrpos($filePath,
"/")) !==
false)
970 $filePath = mb_substr($filePath, 0, $slashPos);
971 if(is_dir($filePath.
"/lang"))
973 $langDirTo = $filePath.
"/lang";
974 $fileNameTo = mb_substr($fileTo, $slashPos);
981 $langs = self::$languageList;
985 if (file_exists($langDir.
"/".
$lang.$fileName))
987 include($langDir.
"/".
$lang.$fileName);
992 if (file_exists($langDirTo.
"/".
$lang.$fileNameTo))
994 include($langDirTo.
"/".
$lang.$fileNameTo);
998 @mkdir(dirname($langDirTo.
"/".
$lang.$fileNameTo), 0777,
true);
1002 foreach(
$MESS as $c => $m)
1004 $s .=
"\$MESS['".EscapePHPString($c).
"'] = \"".
EscapePHPString($m).
"\";\n";
1006 file_put_contents($langDirTo.
"/".
$lang.$fileNameTo, $s);
1014 public static function FindAndCopy($sourceDir,
$lang,
$pattern, $destinationFile)
1016 $insideLangDir = (mb_strpos($sourceDir.
"/",
"/lang/".$lang.
"/") !==
false);
1018 foreach(scandir($sourceDir) as $file)
1020 if($file ==
"." || $file ==
"..")
1025 if($file ==
".description.php" || $file ==
".parameters.php")
1030 if($sourceDir.
"/".$file == $destinationFile)
1035 if(is_dir($sourceDir.
"/".$file))
1037 self::FindAndCopy($sourceDir.
"/".$file,
$lang,
$pattern, $destinationFile);
1042 include($sourceDir.
"/".$file);
1044 $copyMess =
array();
1053 if(!empty($copyMess))
1055 foreach(self::$languageList as $destLang)
1057 if($destLang <>
$lang)
1060 $sourceFile = str_replace(
"/lang/".
$lang.
"/",
"/lang/".$destLang.
"/", $sourceDir.
"/".$file);
1061 if(file_exists($sourceFile))
1063 include($sourceFile);
1066 $destMess =
array();
1069 if(isset($copyMess[
$code]))
1074 $destFile = str_replace(
"/lang/".
$lang.
"/",
"/lang/".$destLang.
"/", $destinationFile);
1078 $destMess = $copyMess;
1079 $destFile = $destinationFile;
1083 if(file_exists($destFile))
1089 @mkdir(dirname($destFile), 0777,
true);
1096 echo $sourceDir.
"/".$file.
": ".
$code.
" already exists in the destination file.\n";
1105 foreach(
$MESS as $c => $m)
1107 $s .=
"\$MESS['".EscapePHPString($c).
"'] = \"".
EscapePHPString($m).
"\";\n";
1109 file_put_contents($destFile, $s);
1130function GetPhraseCounters($arCommon, $entry, $enabledLanguages)
1132 global $arCommonCounter, $Counter;
1135 $path = $entry[
"PATH"];
1143 if ($entry[
'IS_DIR'] ===
'Y')
1148 foreach ($enabledLanguages as $lng)
1151 $pathLength = mb_strlen(
$path);
1153 foreach($arCommon as
$arr)
1155 if(
$arr[
'IS_DIR'] ==
'N' && (strncmp(
$arr[
'PATH'],
$path, $pathLength) == 0))
1164 if (is_array($arCommon))
1166 $pathLength = mb_strlen(
$path);
1168 foreach ($arCommon as
$arr)
1170 if(
$arr[
'IS_DIR']==
'N' && (strncmp(
$arr[
'PATH'],
$path, $pathLength) == 0))
1180 foreach ($enabledLanguages as $lng)
1184 $pathLength = mb_strlen(
$path);
1186 foreach($arCommon as
$arr)
1188 if(
$arr[
'IS_DIR'] ==
'N' && (strncmp(
$arr[
'PATH'],
$path, $pathLength) == 0))
1196 $arFilesLng =
array();
1201 if(file_exists($file) && preg_match(
"#/lang/([^/]*?)/#", $file, $arMatch))
1203 $file_lang = $arMatch[1];
1204 if(in_array($file_lang, $enabledLanguages))
1206 if(mb_substr($file, -4) !=
'.php')
1218 $arFilesLngCounter =
array();
1220 foreach($arFilesLng as
$fileName => $arLns)
1222 $total_arr =
array();
1225 foreach($arLns as $ln => $arLn)
1227 $total_arr = array_merge($total_arr, $arLn);
1229 $total_arr = array_unique($total_arr);
1230 $total =
count($total_arr);
1232 foreach($enabledLanguages as
$lang)
1236 $diff = array_diff($total_arr, $arLn);
1237 $arr[
"TOTAL"] = $total;
1243 foreach($arFilesLngCounter as
$fileName => $arCount)
1245 foreach($arCount as $ln => $arLn)
1247 $file_path = str_replace(
"/lang/",
"/lang/".$ln.
"/",
$fileName);
1248 $arCommonCounter[
$key][$ln][$file_path][
"TOTAL"] += $arLn[
"TOTAL"];
1249 $arCommonCounter[
$key][$ln][$file_path][
"DIFF"] += $arLn[
"DIFF"];
1262function removePhrasesByMasterFile($masterLanguage, $listIds, &$errorCollection)
1272 $currentFileList = [];
1273 $currentFileListAbs = [];
1274 $masterFileList = [];
1277 if (!$row[
'IS_LANG'])
1281 $file = $row[
'FILE'];
1282 if (!isset($currentFileList[$file]))
1284 $currentFileList[$file] = [];
1285 $currentFileListAbs[$file] = [];
1287 $currentFileList[$file][$row[
'LANG']] = $row[
'PATH'];
1288 $currentFileListAbs[$file][$row[
'LANG']] = $row[
'FULL_PATH'];
1289 if ($row[
'LANG'] == $masterLanguage)
1291 $masterFileList[$file] =
true;
1296 if (empty($masterFileList))
1301 foreach ($listIds as $file)
1303 $masterFileIsFounded =
false;
1305 if (isset($masterFileList[$file]))
1308 if (file_exists($currentFileListAbs[$file][$masterLanguage]))
1310 $masterFileIsFounded =
true;
1312 include($currentFileListAbs[$file][$masterLanguage]);
1316 $masterMask = array_fill_keys(array_keys(
$MESS),
true);
1319 if (!$masterFileIsFounded || empty($masterMask))
1326 foreach ($currentFileList[$file] as $phraseLanguage => $phrasePath)
1328 if ($phraseLanguage == $masterLanguage)
1334 $phrasePathAbs = $currentFileListAbs[$file][$phraseLanguage];
1335 if (file_exists($phrasePathAbs))
1338 include($phrasePathAbs);
1342 $MESS = array_intersect_key(
$MESS, $masterMask);
1345 $newList[$phrasePath] =
$MESS;
1346 $newListAbs[$phrasePath] = $phrasePathAbs;
1348 unset($phrasePath, $phrasePathAbs);
1350 if (empty($newList))
1355 foreach ($newList as $langFileName => $phrases)
1357 saveTranslationFile($langFileName, $phrases, $errorCollection);
1359 unset($langFileName, $phrases, $newList);
1375function saveTranslationFile($langFileName, $phrases, &$errorCollection)
1380 if ($langId !=
'ru')
1382 ksort($phrases, SORT_STRING);
1386 foreach ($phrases as $phraseId => $phrase)
1388 $phrase = str_replace([
"\r\n",
"\r"], [
"\n",
''], $phrase);
1392 unset($phraseId, $phrase, $row);
1396 $errorCollection[] = Loc::getMessage(
'TR_CREATE_BACKUP_ERROR',
array(
'%FILE%' => $langFileName));
1403 if (in_array($langId,
Translate\Config::getTranslationRepositoryLanguages()))
1409 $checkFullPath = realpath($fullPath);
1413 $file =
new Translate\IO\File(
Translate\
IO\Path::tidy($fullPath));
1417 if ($file->putContents(
'<?'.
$content.
"\n?".
'>') ===
false)
1419 $errorCollection[] = Loc::getMessage(
'TR_TOOLS_ERROR_WRITE_FILE',
array(
'%FILE%' => $langFileName));
1424 if ($file->isExists())
1426 $file->markWritable();
static getSourceEncoding($lang)
static useTranslationRepository()
static getCurrentEncoding()
static convertLangPath($langFile, $language)
static detectUtf8($string, $replaceHex=true)
static getCultureEncoding(string $languageId)
static getEnabledLanguages()
static replaceLangId(string $path, string $langId)
static tidy(string $path)
static isLangDir(string $path, bool $additionalCheck=false)
static extractLangId(string $path)
static checkCreatePath(string $path)
static removeLangId(string $path, ?array $langs=null)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
while($arParentIBlockProperty=$dbParentIBlockProperty->Fetch()) $errorMessage
$_SERVER["DOCUMENT_ROOT"]
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
if(!defined('SITE_ID')) $lang
EscapePHPString($str, $encloser='"')
RegisterModuleDependences($FROM_MODULE_ID, $MESSAGE_ID, $TO_MODULE_ID, $TO_CLASS="", $TO_METHOD="", $SORT=100, $TO_PATH="", $TO_METHOD_ARG=[])
UnRegisterModuleDependences($FROM_MODULE_ID, $MESSAGE_ID, $TO_MODULE_ID, $TO_CLASS="", $TO_METHOD="", $TO_PATH="", $TO_METHOD_ARG=[])
Rel2Abs($curdir, $relpath)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if(empty($signedUserToken)) $key
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
if(!Loader::includeModule('sale')) $pattern