- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/lib/localization/translation.php
- Класс: BitrixMainLocalizationTranslation
- Вызов: Translation::convertLangPath
static function convertLangPath($langFile, $language)
{
if (empty($language) || !(self::useTranslationRepository() || self::getDeveloperRepositoryPath() !== null))
{
return $langFile;
}
static $documentRoot;
if ($documentRoot === null)
{
$documentRoot = Path::normalize(MainApplication::getDocumentRoot());
}
if (self::useTranslationRepository() && !self::isDefaultTranslationLang($language))
{
$modulePath = self::getTranslationRepositoryPath().'/'.$language.'/';
}
elseif (self::getDeveloperRepositoryPath() !== null)
{
$modulePath = self::getDeveloperRepositoryPath(). '/';
}
elseif (self::isDefaultTranslationLang($language))
{
$modulePath = $documentRoot. '/bitrix/modules/';
}
else
{
return $langFile;
}
if (strpos($langFile, '\') !== false)
{
$langFile = str_replace('\', '/', $langFile);
}
if (strpos($langFile, '//') !== false)
{
$langFile = str_replace('//', '/', $langFile);
}
// linked
if (self::getDeveloperRepositoryPath() !== null)
{
if (mb_strpos($langFile, self::getDeveloperRepositoryPath()) === 0)
{
$langFile = str_replace(
self::getDeveloperRepositoryPath(). '/',
$modulePath,
$langFile
);
return $langFile;
}
}
// module lang
if (strpos($langFile, $documentRoot. '/bitrix/modules/') === 0)
{
$langFile = str_replace(
$documentRoot.'/bitrix/modules/',
$modulePath,
$langFile
);
return $langFile;
}
self::loadMap();
$langPathParts = preg_split('#[/]+#', trim(str_replace($documentRoot, '', $langFile), '/'), 6);
if (
empty($langPathParts)
|| $langPathParts[0] !== 'bitrix'
|| empty($langPathParts[1])
|| empty($langPathParts[2])
|| empty($langPathParts[3])
)
{
return $langFile;
}
$testEntry = $langPathParts[1];
switch ($testEntry)
{
// bitrix/mobileapp/[moduleName] -> [moduleName]/install/mobileapp/[moduleName]
case 'mobileapp':
$moduleName = $langPathParts[2];
if (isset(self::$map[$moduleName][$testEntry], self::$map[$moduleName][$testEntry][$moduleName]))
{
$testEntry = 'mobileapp/'. $moduleName;
$langFile = str_replace(
$documentRoot.'/bitrix/mobileapp/'. $moduleName. '/',
$modulePath.''.$moduleName.'/install/mobileapp/'. $moduleName. '/',
$langFile
);
}
break;
// bitrix/templates/[templateName] -> [moduleName]/install/templates/[templateName]
case 'templates':
$templateName = $langPathParts[2];
foreach (self::$map as $moduleName => $moduleEntries)
{
if (isset(self::$map[$moduleName][$testEntry], self::$map[$moduleName][$testEntry][$templateName]))
{
$langFile = str_replace(
$documentRoot.'/bitrix/templates/'.$templateName.'/',
$modulePath.''.$moduleName.'/install/templates/'. $templateName .'/',
$langFile
);
break;
}
}
break;
// bitrix/components/bitrix/[componentName] -> [moduleName]/install/components/bitrix/[componentName]
// bitrix/activities/bitrix/[activityName] -> [moduleName]/install/activities/bitrix/[activityName]
// bitrix/wizards/bitrix/[wizardsName] -> [moduleName]/install/wizards/bitrix/[wizardsName]
// bitrix/gadgets/bitrix/[gadgetName] -> [moduleName]/install/gadgets/bitrix/[gadgetName]
case 'components':
case 'activities':
case 'wizards':
case 'gadgets':
case 'blocks':
if ($langPathParts[2] !== 'bitrix')
{
break;
}
$searchEntryName = $langPathParts[3];
foreach (self::$map as $moduleName => $moduleEntries)
{
if (isset(self::$map[$moduleName][$testEntry], self::$map[$moduleName][$testEntry][$searchEntryName]))
{
$langFile = str_replace(
$documentRoot.'/bitrix/'.$testEntry.'/bitrix/'.$searchEntryName.'/',
$modulePath.''.$moduleName.'/install/'.$testEntry.'/bitrix/'. $searchEntryName. '/',
$langFile
);
break;
}
}
break;
// bitrix/js/[moduleName]/[smth] -> [moduleName]/install/js/[moduleName]/[smth]
// bitrix/js/[moduleName]/[smth] -> [moduleName]/install/public/js/[moduleName]/[smth]
case 'js':
$libraryNamespace = $langPathParts[2]. '/'. $langPathParts[3];
foreach (self::$map as $moduleName => $moduleEntries)
{
if (isset(self::$map[$moduleName][$testEntry], self::$map[$moduleName][$testEntry][$libraryNamespace]))
{
$langFile = str_replace(
$documentRoot.'/bitrix/'.$testEntry.'/'.$libraryNamespace.'/',
$modulePath.''.$moduleName.'/install/'.$testEntry.'/'.$libraryNamespace.'/',
$langFile
);
break;
}
if (isset(self::$map[$moduleName]["public/{$testEntry}"], self::$map[$moduleName]["public/{$testEntry}"][$libraryNamespace]))
{
$langFile = str_replace(
$documentRoot.'/bitrix/'.$testEntry.'/'.$libraryNamespace.'/',
$modulePath.''.$moduleName.'/install/public/'.$testEntry.'/'.$libraryNamespace.'/',
$langFile
);
break;
}
}
break;
// bitrix/[moduleName]/payment/[paymentHandler] -> [moduleName]/payment/[paymentHandler]
case 'payment':
$searchEntryName = $langPathParts[3];
foreach (self::$map as $moduleName => $moduleEntries)
{
if (isset(self::$map[$moduleName][$testEntry], self::$map[$moduleName][$testEntry][$searchEntryName]))
{
$langFile = str_replace(
$documentRoot.'/bitrix/modules/'.$moduleName.'/'.$testEntry.'/',
$modulePath.''.$moduleName.'/'.$testEntry.'/',
$langFile
);
break;
}
}
break;
}
return $langFile;
}