• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/localization/loc.php
  • Класс: BitrixMainLocalizationLoc
  • Вызов: Loc::includeLangFiles
static function includeLangFiles($file, $language, &$loadedLangFile)
{
	static $langDirCache = array();

	// open_basedir restriction
	static $openBasedir = [], $openBasedirRestriction;
	if ($openBasedirRestriction === null)
	{
		$openBasedirTmp = ini_get('open_basedir');
		if (!empty($openBasedirTmp))
		{
			// multiple paths split by colon ":" - "/home/bitrix:/var/www/html"
			// under non windows by semicolon ";" - "c:/www/;c:/www/html"
			$openBasedirTmp = explode(
				(strncasecmp(PHP_OS, 'WIN', 3) == 0 ? ';' : ':'),
				$openBasedirTmp
			);
			foreach ($openBasedirTmp as $testDir)
			{
				if (!empty($testDir))
				{
					$testDir = Path::normalize($testDir);
					if (is_dir($testDir))
					{
						$openBasedir[] = $testDir;
					}
				}
			}
		}
		$openBasedirRestriction = !empty($openBasedir);
	}

	$path = Path::getDirectory($file);

	if(isset($langDirCache[$path]))
	{
		$langDir = $langDirCache[$path];
		$fileName = mb_substr($file, (mb_strlen($langDir) - 5));
	}
	else
	{
		//let's find language folder
		$langDir = $fileName = '';
		$filePath = $file;
		while (($slashPos = mb_strrpos($filePath, '/')) !== false)
		{
			$filePath = mb_substr($filePath, 0, $slashPos);
			if ($openBasedirRestriction === true)
			{
				$withinOpenBasedir = false;
				foreach ($openBasedir as $testDir)
				{
					if (stripos($filePath, $testDir) === 0)
					{
						$withinOpenBasedir = true;
						break;
					}
				}
				if (!$withinOpenBasedir)
				{
					break;
				}
			}
			$langPath = $filePath. '/lang';
			if (is_dir($langPath))
			{
				$langDir = $langPath;
				$fileName = mb_substr($file, $slashPos);
				$langDirCache[$path] = $langDir;
				break;
			}
		}
	}

	$mess = array();
	if($langDir <> '')
	{
		//load messages for default lang first
		$defaultLang = self::getDefaultLang($language);
		if($defaultLang <> $language)
		{
			$langFile = $langDir. '/'. $defaultLang. $fileName;

			$langFile = Translation::convertLangPath($langFile, $defaultLang);

			if(file_exists($langFile))
			{
				$mess = self::includeFile($langFile);
				$loadedLangFile = $langFile;
			}
		}

		//then load messages for specified lang
		$langFile = $langDir. '/'. $language. $fileName;

		$langFile = Translation::convertLangPath($langFile, $language);

		if(file_exists($langFile))
		{
			$mess = array_merge($mess, self::includeFile($langFile));
			$loadedLangFile = $langFile;
		}
	}

	return $mess;
}