diff --git a/src/helpers.php b/src/helpers.php index 2b0d6c3..5c24965 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -1,7 +1,6 @@ file->file_name], $phrase->key, $phrase->value); + setArrayValue( + array: $tree[$locale][$phrase->file->file_name], + key: $phrase->key, + value: ! blank($phrase->value) ? $phrase->value : $phrase->source->value + ); } return $tree; } } +if (! function_exists('setArrayValue')) { + function setArrayValue(&$array, $key, $value) + { + if (is_null($key)) { + return $array = $value; + } + + $keys = preg_split('/\.(?=[^.]*[^.])/', $key); + + foreach ($keys as $i => $key) { + if (blank($value)) { + dd($key, $value); + } + + if (count($keys) === 1) { + break; + } + + unset($keys[$i]); + + if (! isset($array[$key]) || ! is_array($array[$key])) { + $array[$key] = []; + } + + $array = &$array[$key]; + } + + $lastKey = array_shift($keys); + + if (! blank($lastKey)) { + $array[$lastKey] = $value; + } + + return $array; + } +} + if (! function_exists('currentUser')) { function currentUser(): null|Authenticatable|Contributor {