1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
languagenormalizer.php
См. документацию.
1<?php
2namespace Bitrix\Location\Entity\Address\Normalizer;
3
4use Bitrix\Main\IO\File;
5use Bitrix\Main\Localization;
6
15{
17 protected $letters = [];
19 protected $aliases = [];
21 protected $titles = [];
22
28 public function __construct($lang = LANGUAGE_ID, array $langData = [])
29 {
30 if(empty($langData))
31 {
32 $langData = $this->loadLangData($lang);
33 }
34
35 $this->setLangData($langData);
36 }
37
39 public function normalize(string $string): string
40 {
41 $result = $string;
42
43 if(is_array($this->letters) && !empty($this->letters))
44 {
45 $result = $this->replaceLetters($result, $this->letters);
46 }
47
48 if(is_array($this->aliases) && !empty($this->aliases))
49 {
50 $result = $this->replaceAliases($result, $this->aliases);
51 }
52
53 if(is_array($this->titles) && !empty($this->titles))
54 {
55 $result = $this->replaceTitles($result, $this->titles);
56 }
57
58 return $result;
59 }
60
66 protected function replaceLetters(string $string, array $letters): string
67 {
68 $result = $string;
69
70 foreach($letters as $search => $replace)
71 {
72 $result = str_replace($search, $replace, $result);
73 }
74
75 return $result;
76 }
77
83 protected function replaceTitles(string $string, array $titles): string
84 {
85 $result = $string;
86 $implodedTitles = implode('|', $titles);
87 $regexp = '/^('.$implodedTitles.')+\s+(.*?)$/iu';
88 $result = preg_replace($regexp, '$2', $result);
89
90 if($result !== null)
91 {
92 $regexp = '/^(.*?)\s+(' . $implodedTitles . ')+$/iu';
93 $result = preg_replace($regexp, '$1', $result);
94 }
95
96 return $result !== null ? $result : '';
97 }
98
104 protected function replaceAliases(string $string, array $aliases): string
105 {
106 return $aliases[$string] ?? $string;
107 }
108
113 protected function loadLangData(string $lang): array
114 {
115 $result = [];
116
117 if(empty($result))
118 {
119 if ($langDataPath = $this->getLangDataFilePath($lang))
120 {
121 if (File::isFileExists($langDataPath))
122 {
124 {
125 if (class_exists('\Bitrix\Main\Localization\StreamConverter'))
126 {
127 $result = Localization\StreamConverter::include($langDataPath, $lang);
128 }
129 elseif (class_exists('\Bitrix\Main\Localization\SteamConverter'))
130 {
131 $result = Localization\SteamConverter::include($langDataPath, $lang);
132 }
133 }
134 else
135 {
136 $result = require $langDataPath;
137 }
138 }
139 }
140 }
141
142 return $result;
143 }
144
149 protected function getLangDataFilePath(string $lang): string
150 {
151 return $_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/location/lang/'.$lang.'/lib/entity/address/normalizer/langnormdata.php';
152 }
153
157 public function setLangData(array $langData): void
158 {
159 if(isset($langData['LETTERS']) && is_array($langData['LETTERS']))
160 {
161 $this->letters = $langData['LETTERS'];
162 }
163
164 if(isset($langData['ALIASES']) && is_array($langData['ALIASES']))
165 {
166 $this->aliases = $langData['ALIASES'];
167 }
168
169 if(isset($langData['TITLES']) && is_array($langData['TITLES']))
170 {
171 $this->titles = $langData['TITLES'];
172 }
173 }
174}
replaceTitles(string $string, array $titles)
Определения languagenormalizer.php:83
replaceAliases(string $string, array $aliases)
Определения languagenormalizer.php:104
replaceLetters(string $string, array $letters)
Определения languagenormalizer.php:66
__construct($lang=LANGUAGE_ID, array $langData=[])
Определения languagenormalizer.php:28
static allowConvertEncoding()
Определения translation.php:217
</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
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
if(!defined('SITE_ID')) $lang
Определения include.php:91
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393