Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
langasset.php
1<?php
2
4
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 {
28 }
29 elseif ($this->path)
30 {
31 $languages = $this->useAllLangs
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 (mb_strpos($code, $prefix) !== 0)
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 loadLanguageFile($file, $language=null, $normalize=true)
Definition loc.php:224
static deletePrefixes(array $messages, array $prefixes)
Definition langasset.php:93