1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
config.php
См. документацию.
1<?php
2
3namespace Bitrix\Translate;
4
5use Bitrix\Main;
6use Bitrix\Translate;
7use Bitrix\Main\Localization\Loc;
8
9final class Config
10{
11 public const OPTION_INIT_FOLDERS = 'INIT_FOLDERS';
12 public const OPTION_BUTTON_LANG_FILES = 'BUTTON_LANG_FILES';
13 public const OPTION_BACKUP_FILES = 'BACKUP_FILES';
14 public const OPTION_SORT_PHRASES = 'SORT_PHRASES';
15 public const OPTION_DONT_SORT_LANGUAGES = 'DONT_SORT_LANGUAGES';
16 public const OPTION_BACKUP_FOLDER = 'BACKUP_FOLDER';
17 public const OPTION_EXPORT_CSV_DELIMITER = 'EXPORT_CSV_DELIMITER';
18 public const OPTION_EXPORT_FOLDER = 'EXPORT_FOLDER';
19
20 private const CACHE_TTL = 3600;
21
29 public static function getOption(string $optionName): ?string
30 {
31 static $options = [];
32 if (!isset($options[$optionName]))
33 {
35 'translate',
37 self::getModuleDefault($optionName)
38 );
39 }
40
41 return $options[$optionName] ?: null;
42 }
43
51 public static function getModuleDefault(string $optionName): ?string
52 {
53 static $defs;
54 if ($defs === null)
55 {
56 $defs = Main\Config\Option::getDefaults('translate');
57 }
58
59 return !empty($defs[$optionName]) ? $defs[$optionName] : null;
60 }
61
67 public static function getDefaultLanguages(): array
68 {
69 return ['ru', 'en', 'de', 'kz'];
70 }
71
77 public static function isUtfMode(): bool
78 {
79 return true;
80 }
81
87 public static function getAllowedEncodings(): array
88 {
90 }
91
99 public static function getEncodingName(string $encoding): string
100 {
101 static $mess;
102 if ($mess === null)
103 {
104 $mess = Loc::loadLanguageFile(__FILE__);
105 if (empty($mess))
106 {
107 $mess = Loc::loadLanguageFile(__FILE__, 'en');
108 }
109 }
110 $encTitle = Loc::getMessage('TRANSLATE_ENCODING_'.\mb_strtoupper(\str_replace('-', '_', $encoding)));
111 if (!empty($encTitle))
112 {
113 $encTitle .= " ($encoding)";
114 }
115 else
116 {
117 $encTitle = $encoding;
118 $encAlias = self::getAliasEncoding($encoding);
119 if ($encAlias)
120 {
121 $encTitle .= " ($encAlias)";
122 }
123 }
124
125 return $encTitle;
126 }
127
135 public static function getAliasEncoding(string $encoding): ?string
136 {
137 static $aliasEncoding = [
138 'windows-1250' => 'iso-8859-2',
139 'windows-1252' => 'iso-8859-1',
140 ];
141 if (isset($aliasEncoding[$encoding]))
142 {
143 return $aliasEncoding[$encoding];
144 }
145
146 $alias = array_search($encoding, $aliasEncoding);
147 if ($alias !== false)
148 {
149 return $alias;
150 }
151
152 return null;
153 }
154
162 public static function getCultureEncoding(string $languageId): ?string
163 {
164 static $cultureEncoding;
165 if ($cultureEncoding === null)
166 {
167 $cultureEncoding = [];
169 'select' => ['ID', 'CODE', 'CHARSET'],
170 'cache' => ['ttl' => self::CACHE_TTL],
171 ]);
172 while ($row = $iterator->fetch())
173 {
174 $cultureEncoding[\mb_strtolower($row['CODE'])] = \mb_strtolower($row['CHARSET']);
175 }
176 }
177
178 return ($cultureEncoding[$languageId] ?? null) ?: null;
179 }
180
186 public static function getLanguages(bool $skipCache = false): array
187 {
188 static $languages;
189 if ($languages === null)
190 {
191 $languages = [];
193 'select' => ['ID', 'SORT'],
194 'order' => ['SORT' => 'ASC'],
195 'cache' => ['ttl' => $skipCache ? 0 : self::CACHE_TTL],
196 ]);
197 while ($row = $iterator->fetch())
198 {
199 $languages[] = mb_strtolower($row['ID']);
200 }
201 }
202
203 return $languages;
204 }
205
211 public static function getEnabledLanguages(): array
212 {
213 static $languages;
214 if ($languages === null)
215 {
216 $languages = [];
218 'select' => ['ID', 'SORT'],
219 'filter' => ['=ACTIVE' => 'Y'],
220 'order' => ['SORT' => 'ASC'],
221 'cache' => ['ttl' => self::CACHE_TTL],
222 ]);
223 while ($row = $iterator->fetch())
224 {
225 $languages[] = mb_strtolower($row['ID']);
226 }
227 }
228
229 return $languages;
230 }
231
239 public static function getLanguagesTitle(array $languageIds): array
240 {
241 static $cache = [];
242
243 $cacheId = \implode('-', $languageIds);
244 if (!isset($cache[$cacheId]))
245 {
246 $cache[$cacheId] = [];
247
249 'select' => ['ID', 'NAME'],
250 'filter' => [
251 '=ID' => $languageIds,
252 '=ACTIVE' => 'Y'
253 ],
254 'order' => ['SORT' => 'ASC'],
255 'cache' => ['ttl' => self::CACHE_TTL],
256 ]);
257 while ($row = $iterator->fetch())
258 {
259 $cache[$cacheId][mb_strtolower($row['ID'])] = $row['NAME'];
260 }
261 }
262
263 return $cache[$cacheId];
264 }
265
271 public static function getAvailableLanguages(): array
272 {
273 static $languages;
274 if ($languages === null)
275 {
276 $languages = \array_unique(\array_merge(
277 self::getAvailableDefaultLanguages(),
278 self::getTranslationRepositoryLanguages()
279 ));
280 }
281
282 return $languages;
283 }
284
290 public static function getAvailableDefaultLanguages(): array
291 {
292 static $languages;
293 if ($languages === null)
294 {
295 $languages = [];
296 $langDirList = new Main\IO\Directory(Main\Application::getDocumentRoot(). '/bitrix/modules/main/lang/');
297 foreach ($langDirList->getChildren() as $langDir)
298 {
299 $langId = $langDir->getName();
300 if (\in_array($langId, Translate\IGNORE_FS_NAMES, true) || !$langDir->isDirectory())
301 {
302 continue;
303 }
304 $languages[] = $langId;
305 }
306 }
307
308 return $languages;
309 }
310
316 public static function getTranslationRepositoryLanguages(): array
317 {
318 static $languages;
319 if ($languages === null)
320 {
321 $languages = [];
323 {
325 foreach ($langDirList->getChildren() as $langDir)
326 {
327 $langId = $langDir->getName();
328 if (\in_array($langId, Translate\IGNORE_FS_NAMES, true) || !$langDir->isDirectory())
329 {
330 continue;
331 }
332 $languages[] = $langId;
333 }
334 }
335 }
336
337 return $languages;
338 }
339
345 public static function getInitPath(): array
346 {
348 static $initFolders;
349 if ($initFolders === null)
350 {
351 $initFolders = [];
352 $folders = (string)Main\Config\Option::get(
353 'translate',
354 self::OPTION_INIT_FOLDERS,
355 Translate\Config::getModuleDefault(Translate\Config::OPTION_INIT_FOLDERS)
356 );
357 $folders = \explode(',', \trim($folders));
358 foreach ($folders as $oneFolder)
359 {
360 if (!empty($oneFolder))
361 {
362 $oneFolder = Translate\IO\Path::normalize($oneFolder);
363 $initFolders[] = '/'.\ltrim($oneFolder, '/');
364 }
365 }
366 }
367
368 return $initFolders;
369 }
370
376 public static function getDefaultPath(): string
377 {
378 static $defaultPath;
379 if ($defaultPath === null)
380 {
381 $folders = \explode(',', self::getModuleDefault(self::OPTION_INIT_FOLDERS));
382 $defaultPath = $folders[0];
383 }
384
385 return $defaultPath;
386 }
387
388
394 public static function needToBackUpFiles(): bool
395 {
396 static $needToBackUpFiles;
397 if ($needToBackUpFiles === null)
398 {
399 $def = self::getModuleDefault(self::OPTION_BACKUP_FILES);
400 $needToBackUpFiles = (bool)(Main\Config\Option::get('translate', self::OPTION_BACKUP_FILES, $def) === 'Y');
401 }
402
403 return $needToBackUpFiles;
404 }
405
411 public static function getBackupFolder(): string
412 {
413 static $backupFolder;
414 if ($backupFolder === null)
415 {
416 $confOption = Main\Config\Option::get('translate', self::OPTION_BACKUP_FOLDER, '');
417 if (!empty($confOption))
418 {
419 if (\mb_strpos($confOption, '/') === 0)
420 {
421 $backupFolder = $confOption;
422 }
423 elseif (\strncasecmp(\PHP_OS, 'WIN', 3) === 0 && \preg_match("#^[a-z]{1}:/#i", $confOption))
424 {
425 $backupFolder = $confOption;
426 }
427 else
428 {
429 $backupFolder = Main\Application::getDocumentRoot(). '/'. $confOption;
430 }
431 }
432 else
433 {
434 $defOption = self::getModuleDefault(self::OPTION_BACKUP_FOLDER);
435 if (empty($defOption))
436 {
437 $defOption = 'bitrix/backup/translate/';
438 }
439 $backupFolder = Main\Application::getDocumentRoot(). '/'. $defOption;
440 }
441 }
442
443 return $backupFolder;
444 }
445
451 public static function needToSortPhrases(): bool
452 {
453 static $needToSortPhrases;
454 if ($needToSortPhrases === null)
455 {
456 $def = self::getModuleDefault(self::OPTION_SORT_PHRASES);
457 $needToSortPhrases = (bool)(Main\Config\Option::get('translate', self::OPTION_SORT_PHRASES, $def) === 'Y');
458 }
459
460 return $needToSortPhrases;
461 }
462
468 public static function getNonSortPhraseLanguages(): array
469 {
470 static $nonSortPhraseLanguages;
471 if ($nonSortPhraseLanguages === null)
472 {
473 $nonSortPhraseLanguages = [];
474 $def = self::getModuleDefault(self::OPTION_DONT_SORT_LANGUAGES);
475 $nonSortPhraseLanguages = Main\Config\Option::get('translate', self::OPTION_DONT_SORT_LANGUAGES, $def);
476 if (!is_array($nonSortPhraseLanguages))
477 {
478 $nonSortPhraseLanguages = \explode(',', $nonSortPhraseLanguages);
479 }
480 }
481
482 return $nonSortPhraseLanguages;
483 }
484
490 public static function getExportFolder(): ?string
491 {
492 static $exportFolder = -1;
493 if ($exportFolder === -1)
494 {
495 $exportFolder = null;// '/bitrix/updates/_langs/';
496 $confOption = Main\Config\Option::get('translate', self::OPTION_EXPORT_FOLDER, '');
497 if (!empty($confOption))
498 {
499 if (\mb_strpos($confOption, Main\Application::getDocumentRoot()) === 0)
500 {
501 $exportFolder = $confOption;
502 }
503 else
504 {
505 $exportFolder = Main\Application::getDocumentRoot(). '/'. $confOption;
506 }
507 }
508 }
509
510 return $exportFolder;
511 }
512}
static getDocumentRoot()
Определения application.php:736
static getDefaults($moduleId)
Определения option.php:108
static get($moduleId, $name, $default="", $siteId=false)
Определения option.php:30
static normalize($path)
Определения path.php:22
static useTranslationRepository()
Определения translation.php:173
static getTranslationRepositoryPath()
Определения translation.php:193
static getList(array $parameters=array())
Определения datamanager.php:431
static getAvailableDefaultLanguages()
Определения config.php:290
const OPTION_INIT_FOLDERS
Определения config.php:11
const OPTION_BACKUP_FOLDER
Определения config.php:16
static getCultureEncoding(string $languageId)
Определения config.php:162
static getEncodingName(string $encoding)
Определения config.php:99
static getAvailableLanguages()
Определения config.php:271
const OPTION_EXPORT_CSV_DELIMITER
Определения config.php:17
const OPTION_BACKUP_FILES
Определения config.php:13
static needToSortPhrases()
Определения config.php:451
static getNonSortPhraseLanguages()
Определения config.php:468
static getEnabledLanguages()
Определения config.php:211
static getModuleDefault(string $optionName)
Определения config.php:51
static getLanguages(bool $skipCache=false)
Определения config.php:186
static getBackupFolder()
Определения config.php:411
static getDefaultLanguages()
Определения config.php:67
static getAllowedEncodings()
Определения config.php:87
static getDefaultPath()
Определения config.php:376
const OPTION_SORT_PHRASES
Определения config.php:14
static needToBackUpFiles()
Определения config.php:394
static getAliasEncoding(string $encoding)
Определения config.php:135
const OPTION_BUTTON_LANG_FILES
Определения config.php:12
static getExportFolder()
Определения config.php:490
static isUtfMode()
Определения config.php:77
static getTranslationRepositoryLanguages()
Определения config.php:316
const OPTION_DONT_SORT_LANGUAGES
Определения config.php:15
const OPTION_EXPORT_FOLDER
Определения config.php:18
static getLanguagesTitle(array $languageIds)
Определения config.php:239
static getOption(string $optionName)
Определения config.php:29
$options
Определения commerceml2.php:49
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
Определения autoload.php:3
const ENCODINGS
Определения autoload.php:16
const IGNORE_FS_NAMES
Определения autoload.php:41
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$optionName
Определения options.php:1735
foreach($arTemplatesList as $templ) if(mb_strpos($templ["NAME"] $def
Определения template_copy.php:264
$iterator
Определения yandex_run.php:610