20 private const CACHE_TTL = 3600;
29 public static function getOption(
string $optionName): ?string
32 if (!isset($options[$optionName]))
37 self::getModuleDefault($optionName)
41 return $options[$optionName] ?:
null;
56 $defs = Main\Config\Option::getDefaults(
'translate');
59 return $defs[$optionName] ?:
null;
69 return [
'ru',
'en',
'de'];
82 $flag = Main\Application::isUtfMode() || defined(
'BX_UTF');
116 $encTitle =
Loc::getMessage(
'TRANSLATE_ENCODING_'.\mb_strtoupper(\str_replace(
'-',
'_', $encoding)));
117 if (!empty($encTitle))
119 $encTitle .=
" ($encoding)";
123 $encTitle = $encoding;
124 $encAlias = self::getAliasEncoding($encoding);
127 $encTitle .=
" ($encAlias)";
143 static $aliasEncoding = [
144 'windows-1250' =>
'iso-8859-2',
145 'windows-1252' =>
'iso-8859-1',
147 if (isset($aliasEncoding[$encoding]))
149 return $aliasEncoding[$encoding];
152 $alias = array_search($encoding, $aliasEncoding);
153 if ($alias !==
false)
170 static $cultureEncoding;
171 if ($cultureEncoding ===
null)
173 $cultureEncoding = [];
174 $iterator = Main\Localization\CultureTable::getList([
175 'select' => [
'ID',
'CODE',
'CHARSET'],
176 'cache' => [
'ttl' => self::CACHE_TTL],
178 while ($row = $iterator->fetch())
180 $cultureEncoding[\mb_strtolower($row[
'CODE'])] = \mb_strtolower($row[
'CHARSET']);
184 return ($cultureEncoding[$languageId] ??
null) ?:
null;
195 if ($languages ===
null)
198 $iterator = Main\Localization\LanguageTable::getList([
199 'select' => [
'ID',
'SORT'],
200 'order' => [
'SORT' =>
'ASC'],
201 'cache' => [
'ttl' => self::CACHE_TTL],
203 while ($row = $iterator->fetch())
205 $languages[] = mb_strtolower($row[
'ID']);
220 if ($languages ===
null)
223 $iterator = Main\Localization\LanguageTable::getList([
224 'select' => [
'ID',
'SORT'],
225 'filter' => [
'=ACTIVE' =>
'Y'],
226 'order' => [
'SORT' =>
'ASC'],
227 'cache' => [
'ttl' => self::CACHE_TTL],
229 while ($row = $iterator->fetch())
231 $languages[] = mb_strtolower($row[
'ID']);
249 $cacheId = \implode(
'-', $languageIds);
250 if (!isset($cache[$cacheId]))
252 $cache[$cacheId] = [];
254 $iterator = Main\Localization\LanguageTable::getList([
255 'select' => [
'ID',
'NAME'],
257 '=ID' => $languageIds,
260 'order' => [
'SORT' =>
'ASC'],
261 'cache' => [
'ttl' => self::CACHE_TTL],
263 while ($row = $iterator->fetch())
265 $cache[$cacheId][mb_strtolower($row[
'ID'])] = $row[
'NAME'];
269 return $cache[$cacheId];
280 if ($languages ===
null)
282 $languages = \array_unique(\array_merge(
283 self::getAvailableDefaultLanguages(),
284 self::getTranslationRepositoryLanguages()
299 if ($languages ===
null)
303 foreach ($langDirList->getChildren() as $langDir)
305 $langId = $langDir->getName();
306 if (\in_array($langId, Translate\IGNORE_FS_NAMES,
true) || !$langDir->isDirectory())
310 $languages[] = $langId;
325 if ($languages ===
null)
331 foreach ($langDirList->getChildren() as $langDir)
333 $langId = $langDir->getName();
334 if (\in_array($langId, Translate\IGNORE_FS_NAMES,
true) || !$langDir->isDirectory())
338 $languages[] = $langId;
351 public static function getInitPath(): array
355 if ($initFolders ===
null)
360 self::OPTION_INIT_FOLDERS,
361 Translate\Config::getModuleDefault(Translate\Config::OPTION_INIT_FOLDERS)
363 $folders = \explode(
',', \trim($folders));
364 foreach ($folders as $oneFolder)
366 if (!empty($oneFolder))
368 $oneFolder = Translate\IO\Path::normalize($oneFolder);
369 $initFolders[] =
'/'.\ltrim($oneFolder,
'/');
385 if ($defaultPath ===
null)
387 $folders = \explode(
',', self::getModuleDefault(self::OPTION_INIT_FOLDERS));
388 $defaultPath = $folders[0];
402 static $needToBackUpFiles;
403 if ($needToBackUpFiles ===
null)
405 $def = self::getModuleDefault(self::OPTION_BACKUP_FILES);
406 $needToBackUpFiles = (bool)(Main\
Config\
Option::get(
'translate', self::OPTION_BACKUP_FILES, $def) ===
'Y');
409 return $needToBackUpFiles;
419 static $backupFolder;
420 if ($backupFolder ===
null)
422 $confOption = Main\Config\Option::get(
'translate', self::OPTION_BACKUP_FOLDER,
'');
423 if (!empty($confOption))
425 if (\mb_strpos($confOption,
'/') === 0)
427 $backupFolder = $confOption;
429 elseif (\strncasecmp(\PHP_OS,
'WIN', 3) === 0 && \preg_match(
"#^[a-z]{1}:/#i", $confOption))
431 $backupFolder = $confOption;
435 $backupFolder = Main\Application::getDocumentRoot().
'/'. $confOption;
440 $defOption = self::getModuleDefault(self::OPTION_BACKUP_FOLDER);
441 if (empty($defOption))
443 $defOption =
'bitrix/backup/translate/';
445 $backupFolder = Main\Application::getDocumentRoot().
'/'. $defOption;
449 return $backupFolder;
459 static $needToSortPhrases;
460 if ($needToSortPhrases ===
null)
462 $def = self::getModuleDefault(self::OPTION_SORT_PHRASES);
463 $needToSortPhrases = (bool)(Main\
Config\
Option::get(
'translate', self::OPTION_SORT_PHRASES, $def) ===
'Y');
466 return $needToSortPhrases;
476 static $nonSortPhraseLanguages;
477 if ($nonSortPhraseLanguages ===
null)
479 $nonSortPhraseLanguages = [];
480 $def = self::getModuleDefault(self::OPTION_DONT_SORT_LANGUAGES);
481 $nonSortPhraseLanguages = Main\Config\Option::get(
'translate', self::OPTION_DONT_SORT_LANGUAGES, $def);
482 if (!is_array($nonSortPhraseLanguages))
484 $nonSortPhraseLanguages = \explode(
',', $nonSortPhraseLanguages);
488 return $nonSortPhraseLanguages;
498 static $exportFolder = -1;
499 if ($exportFolder === -1)
501 $exportFolder =
null;
502 $confOption = Main\Config\Option::get(
'translate', self::OPTION_EXPORT_FOLDER,
'');
503 if (!empty($confOption))
507 $exportFolder = $confOption;
511 $exportFolder = Main\Application::getDocumentRoot().
'/'. $confOption;
516 return $exportFolder;
static get($moduleId, $name, $default="", $siteId=false)
static loadLanguageFile($file, $language=null, $normalize=true)
static getMessage($code, $replace=null, $language=null)
static useTranslationRepository()
static getTranslationRepositoryPath()
static getAvailableDefaultLanguages()
const OPTION_INIT_FOLDERS
const OPTION_BACKUP_FOLDER
static getCultureEncoding(string $languageId)
static getEncodingName(string $encoding)
static getAvailableLanguages()
const OPTION_EXPORT_CSV_DELIMITER
const OPTION_BACKUP_FILES
static needToSortPhrases()
static getNonSortPhraseLanguages()
static getEnabledLanguages()
static getModuleDefault(string $optionName)
static getDefaultLanguages()
static getAllowedEncodings()
const OPTION_SORT_PHRASES
static needToBackUpFiles()
static getAliasEncoding(string $encoding)
const OPTION_BUTTON_LANG_FILES
static getTranslationRepositoryLanguages()
const OPTION_DONT_SORT_LANGUAGES
const OPTION_EXPORT_FOLDER
static getLanguagesTitle(array $languageIds)
static getOption(string $optionName)