124 if (self::$currentEncoding ===
null)
132 elseif (defined(
'SITE_CHARSET') && (SITE_CHARSET <>
''))
134 $encoding = SITE_CHARSET;
136 elseif (defined(
'LANG_CHARSET') && (LANG_CHARSET <>
''))
138 $encoding = LANG_CHARSET;
143 if ($context instanceof Main\
Context)
145 $culture = $context->getCulture();
148 $encoding = $culture->getCharset();
153 if ($encoding ===
null)
155 if (Configuration::getValue(
'default_charset') !==
null)
157 $encoding = Configuration::getValue(
'default_charset');
159 elseif (defined(
'BX_DEFAULT_CHARSET') && (BX_DEFAULT_CHARSET <>
''))
161 $encoding = BX_DEFAULT_CHARSET;
165 $encoding =
'windows-1251';
169 self::$currentEncoding = mb_strtolower($encoding);
172 return self::$currentEncoding;
185 if (!isset(self::$needConvertEncoding[$language]) || self::$needConvertEncoding[$language] ===
null)
187 self::$needConvertEncoding[$language] =
false;
189 if (self::allowConvertEncoding())
191 if ($targetEncoding ===
null)
196 self::$needConvertEncoding[$language] = ($targetEncoding != $sourceEncoding);
200 return self::$needConvertEncoding[$language];
213 $needConvert =
false;
214 if (self::allowConvertEncoding())
216 if (self::getDeveloperRepositoryPath() !==
null)
218 $needConvert = (stripos($langFile, self::getDeveloperRepositoryPath()) === 0);
220 if (!$needConvert && self::useTranslationRepository())
222 $needConvert = (stripos($langFile, self::getTranslationRepositoryPath()) === 0);
256 if(self::$translationRepositoryPath ===
null)
258 $config = Configuration::getValue(
'translation');
260 if ($config !==
null && !empty($config[
'translation_repository']))
262 $translationRepositoryPath = realpath($config[
'translation_repository']);
263 if (file_exists($translationRepositoryPath))
265 self::$translationRepositoryPath = Path::normalize($translationRepositoryPath);
270 return self::$translationRepositoryPath;
280 if(self::$allowConvertEncoding ===
null)
282 self::$allowConvertEncoding =
false;
284 $config = Configuration::getValue(
'translation');
286 if ($config !==
null && !empty($config[
'convert_encoding']))
288 self::$allowConvertEncoding = ($config[
'convert_encoding'] ===
true);
292 return self::$allowConvertEncoding;
302 static $developerRepositoryPath, $wasChecked;
303 if($wasChecked ===
null)
306 $config = Configuration::getValue(
'translation');
308 if ($config !==
null && !empty($config[
'developer_repository']))
310 $developerRepositoryPath = realpath($config[
'developer_repository']);
311 if (file_exists($developerRepositoryPath))
313 $developerRepositoryPath = Path::normalize($developerRepositoryPath);
318 return $developerRepositoryPath;
330 if (empty($language) || !(self::useTranslationRepository() || self::getDeveloperRepositoryPath() !==
null))
335 static $documentRoot;
336 if ($documentRoot ===
null)
341 if (self::useTranslationRepository() && !self::isDefaultTranslationLang($language))
345 elseif (self::getDeveloperRepositoryPath() !==
null)
349 elseif (self::isDefaultTranslationLang($language))
351 $modulePath = $documentRoot.
'/bitrix/modules/';
358 if (strpos($langFile,
'\\') !==
false)
360 $langFile = str_replace(
'\\',
'/', $langFile);
362 if (strpos($langFile,
'//') !==
false)
364 $langFile = str_replace(
'//',
'/', $langFile);
368 if (self::getDeveloperRepositoryPath() !==
null)
370 if (mb_strpos($langFile, self::getDeveloperRepositoryPath()) === 0)
372 $langFile = str_replace(
373 self::getDeveloperRepositoryPath().
'/',
383 if (strpos($langFile, $documentRoot.
'/bitrix/modules/') === 0)
385 $langFile = str_replace(
386 $documentRoot.
'/bitrix/modules/',
396 $langPathParts = preg_split(
'#[/]+#', trim(str_replace($documentRoot,
'', $langFile),
'/'), 6);
398 empty($langPathParts)
399 || $langPathParts[0] !==
'bitrix'
400 || empty($langPathParts[1])
401 || empty($langPathParts[2])
402 || empty($langPathParts[3])
408 $testEntry = $langPathParts[1];
413 $moduleName = $langPathParts[2];
414 if (isset(self::$map[$moduleName][$testEntry], self::$map[$moduleName][$testEntry][$moduleName]))
416 $testEntry =
'mobileapp/'. $moduleName;
417 $langFile = str_replace(
418 $documentRoot.
'/bitrix/mobileapp/'. $moduleName.
'/',
419 $modulePath.
''.$moduleName.
'/install/mobileapp/'. $moduleName.
'/',
427 $templateName = $langPathParts[2];
428 foreach (self::$map as $moduleName => $moduleEntries)
430 if (isset(self::$map[$moduleName][$testEntry], self::$map[$moduleName][$testEntry][$templateName]))
432 $langFile = str_replace(
433 $documentRoot.
'/bitrix/templates/'.$templateName.
'/',
434 $modulePath.
''.$moduleName.
'/install/templates/'. $templateName .
'/',
451 if ($langPathParts[2] !==
'bitrix')
455 $searchEntryName = $langPathParts[3];
456 foreach (self::$map as $moduleName => $moduleEntries)
458 if (isset(self::$map[$moduleName][$testEntry], self::$map[$moduleName][$testEntry][$searchEntryName]))
460 $langFile = str_replace(
461 $documentRoot.
'/bitrix/'.$testEntry.
'/bitrix/'.$searchEntryName.
'/',
462 $modulePath.
''.$moduleName.
'/install/'.$testEntry.
'/bitrix/'. $searchEntryName.
'/',
473 $libraryNamespace = $langPathParts[2].
'/'. $langPathParts[3];
475 foreach (self::$map as $moduleName => $moduleEntries)
477 if (isset(self::$map[$moduleName][$testEntry], self::$map[$moduleName][$testEntry][$libraryNamespace]))
479 $langFile = str_replace(
480 $documentRoot.
'/bitrix/'.$testEntry.
'/'.$libraryNamespace.
'/',
481 $modulePath.
''.$moduleName.
'/install/'.$testEntry.
'/'.$libraryNamespace.
'/',
486 if (isset(self::$map[$moduleName][
"public/{$testEntry}"], self::$map[$moduleName][
"public/{$testEntry}"][$libraryNamespace]))
488 $langFile = str_replace(
489 $documentRoot.
'/bitrix/'.$testEntry.
'/'.$libraryNamespace.
'/',
490 $modulePath.
''.$moduleName.
'/install/public/'.$testEntry.
'/'.$libraryNamespace.
'/',
500 $searchEntryName = $langPathParts[3];
501 foreach (self::$map as $moduleName => $moduleEntries)
503 if (isset(self::$map[$moduleName][$testEntry], self::$map[$moduleName][$testEntry][$searchEntryName]))
505 $langFile = str_replace(
506 $documentRoot.
'/bitrix/modules/'.$moduleName.
'/'.$testEntry.
'/',
507 $modulePath.
''.$moduleName.
'/'.$testEntry.
'/',
527 if (empty(self::$map))
529 $cacheManager = Main\Application::getInstance()->getManagedCache();
530 if ($cacheManager->read(static::CACHE_TTL, static::CACHE_ID))
532 self::$map = $cacheManager->get(static::CACHE_ID);
536 if (empty(self::$map))
538 $testForExistence = array(
550 $bxRoot = Main\Application::getDocumentRoot().
'/bitrix/modules/';
552 foreach ($modulesList->getChildren() as $moduleDirectory)
554 if ($moduleDirectory->isDirectory())
556 $moduleName = $moduleDirectory->getName();
557 if (strpos($moduleName,
'.') ===
false || strpos($moduleName,
'bitrix.') === 0)
559 self::$map[$moduleName] = array();
560 foreach ($testForExistence as $testEntry)
562 $testPath = $bxRoot.
'/'. $moduleName.
'/install/'. $testEntry;
563 if ($testEntry ===
'templates' || $testEntry ===
'mobileapp')
567 elseif ($testEntry ===
'js' || $testEntry ===
'public/js')
569 $testPath .=
'/'. $moduleName.
'/';
571 elseif ($testEntry ===
'payment')
573 $testPath = $bxRoot.
'/'. $moduleName.
'/'. $testEntry;
577 $testPath .=
'/bitrix/';
581 if ($testDirectory->isExists())
583 self::$map[$moduleName][$testEntry] = array();
584 foreach ($testDirectory->getChildren() as $testDirectoryEntry)
586 if ($testDirectoryEntry->isDirectory())
588 if ($testEntry ===
'js' || $testEntry ===
'public/js')
590 self::$map[$moduleName][$testEntry][$moduleName.
'/'.$testDirectoryEntry->getName()] = 1;
594 self::$map[$moduleName][$testEntry][$testDirectoryEntry->getName()] = 1;
604 $cacheManager->set(static::CACHE_ID, static::$map);
617 static $encodingCache = array();
619 if(isset($encodingCache[$language]))
621 list($convertEncoding, $targetEncoding, $sourceEncoding) = $encodingCache[$language];
626 $targetEncoding = $sourceEncoding =
'';
633 $encodingCache[$language] = array($convertEncoding, $targetEncoding, $sourceEncoding);
641 return array($convertEncoding, $targetEncoding, $sourceEncoding);