Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
langasset.php
1
<?php
2
3
namespace
Bitrix\Main\Web\WebPacker\Resource
;
4
5
use
Bitrix\Main
;
6
use
Bitrix\Main\Localization\Loc
;
7
13
class
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
32
?
self::getLanguages
()
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
(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
}
Bitrix\Main\IO\Directory
Definition
directory.php:6
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadLanguageFile
static loadLanguageFile($file, $language=null, $normalize=true)
Definition
loc.php:224
Bitrix\Main\Localization\Loc\getCurrentLang
static getCurrentLang()
Definition
loc.php:78
Bitrix\Main\Web\WebPacker\Resource\Asset
Definition
asset.php:16
Bitrix\Main\Web\WebPacker\Resource\Asset\$path
$path
Definition
asset.php:25
Bitrix\Main\Web\WebPacker\Resource\Asset\$content
$content
Definition
asset.php:29
Bitrix\Main\Web\WebPacker\Resource\Asset\LANG
const LANG
Definition
asset.php:20
Bitrix\Main\Web\WebPacker\Resource\LangAsset
Definition
langasset.php:14
Bitrix\Main\Web\WebPacker\Resource\LangAsset\isExists
static isExists($path)
Definition
langasset.php:119
Bitrix\Main\Web\WebPacker\Resource\LangAsset\getContent
getContent()
Definition
langasset.php:23
Bitrix\Main\Web\WebPacker\Resource\LangAsset\$type
$type
Definition
langasset.php:15
Bitrix\Main\Web\WebPacker\Resource\LangAsset\getLanguages
static getLanguages()
Definition
langasset.php:124
Bitrix\Main\Web\WebPacker\Resource\LangAsset\toCamelCase
static toCamelCase(array $messages)
Definition
langasset.php:72
Bitrix\Main\Web\WebPacker\Resource\LangAsset\$useAllLangs
$useAllLangs
Definition
langasset.php:16
Bitrix\Main\Web\WebPacker\Resource\LangAsset\useAllLangs
useAllLangs($use)
Definition
langasset.php:60
Bitrix\Main\Web\WebPacker\Resource\LangAsset\deletePrefixes
static deletePrefixes(array $messages, array $prefixes)
Definition
langasset.php:93
Bitrix\Main\Web\WebPacker\Resource
Definition
asset.php:3
Bitrix\Main
modules
main
lib
web
webpacker
resource
langasset.php
Создано системой
1.10.0