1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
langasset.php
См. документацию.
1<?php
2
3namespace Bitrix\Main\Web\WebPacker\Resource;
4
5use Bitrix\Main;
6use Bitrix\Main\Localization\Loc;
7
13class LangAsset extends Asset
14{
15 protected $type = self::LANG;
16 protected $useAllLangs = false;
17
23 public function getContent()
24 {
25 if (is_array($this->content) && !empty($this->content))
26 {
27 return [Loc::getCurrentLang() => $this->content];
28 }
29 elseif ($this->path)
30 {
31 $languages = $this->useAllLangs
33 : [Loc::getCurrentLang()];
34
35 $result = [];
36 foreach ($languages as $language)
37 {
38 $messages = Loc::loadLanguageFile(
39 self::getAbsolutePath($this->path),
40 $language
41 );
42 if (!empty($messages))
43 {
44 $result[$language] = $messages;
45 }
46 }
47
48 return $result;
49 }
50
51 return [];
52 }
53
60 public function useAllLangs($use)
61 {
62 $this->useAllLangs = (bool) $use;
63 return $this;
64 }
65
72 public static function toCamelCase(array $messages)
73 {
74 foreach ($messages as $code => $value)
75 {
76 unset($messages[$code]);
77 $code = str_replace('_', ' ', mb_strtolower($code));
78 $code = str_replace(' ', '', ucwords($code));
79 $code = lcfirst($code);
80 $messages[$code] = $value;
81 }
82
83 return $messages;
84 }
85
93 public static function deletePrefixes(array $messages, array $prefixes)
94 {
95 foreach ($messages as $code => $value)
96 {
97 foreach ($prefixes as $prefix)
98 {
99 if (!str_starts_with($code, $prefix))
100 {
101 continue;
102 }
103
104 unset($messages[$code]);
105 $code = mb_substr($code, mb_strlen($prefix));
106 $messages[$code] = $value;
107 }
108 }
109
110 return $messages;
111 }
112
119 public static function isExists($path)
120 {
121 return true;
122 }
123
124 protected static function getLanguages()
125 {
126 static $list = null;
127 if ($list !== null)
128 {
129 return $list;
130 }
131
132 $langDir = Main\Application::getDocumentRoot() . '/bitrix/modules/main/lang/';
133 $dir = new Main\IO\Directory($langDir);
134 if ($dir->isExists())
135 {
136 foreach($dir->getChildren() as $childDir)
137 {
138 if (!$childDir->isDirectory())
139 {
140 continue;
141 }
142
143 $list[] = $childDir->getName();
144 }
145 }
146
147 return $list;
148 }
149}
static getDocumentRoot()
Определения application.php:736
static toCamelCase(array $messages)
Определения langasset.php:72
static deletePrefixes(array $messages, array $prefixes)
Определения langasset.php:93
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$dir
Определения quickway.php:303
$messages
Определения template.php:8
path
Определения template_copy.php:201