if (! function_exists('attr_label')) { /** * Русская подпись атрибута: 'volume_ml' → «Объём, мл», 'material' → «Материал». */ function attr_label(string $key): string { static $map = null; if ($map === null) { $cfg = config('AttrLabels'); $map = $cfg->labels ?? []; } if (isset($map[$key])) { return $map[$key]; } // неизвестный ключ: подчёркивания в пробелы, первая буква заглавная $label = str_replace('_', ' ', $key); $label = (string) preg_replace('/\s+/u', ' ', trim($label)); // единицы измерения в технических ключах if (preg_match('/_ml$/u', $key)) { return mb_convert_case($label . ', мл', MB_CASE_TITLE, 'UTF-8'); } if (preg_match('/_g$/u', $key)) { return mb_convert_case($label . ', г', MB_CASE_TITLE, 'UTF-8'); } if (preg_match('/_mm$/u', $key)) { return mb_convert_case($label . ', мм', MB_CASE_TITLE, 'UTF-8'); } return mb_strtoupper(mb_substr($label, 0, 1, 'UTF-8'), 'UTF-8') . mb_substr($label, 1, null, 'UTF-8'); } } ""