From 104efa1470a800d64e2af3a1f49fb67ce2569a11 Mon Sep 17 00:00:00 2001 From: Khaled Huthaily Date: Sun, 25 May 2025 18:07:16 -0600 Subject: [PATCH] output translation array as short array syntax The PR replaces `var_export()` with a custom short array syntax exporter to modernize output and make translation files cleaner, easier to read, and similar to Laravel's default structure. The result will be `return [];` instead of `return array()`. --- src/Manager.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Manager.php b/src/Manager.php index b33530a3..fea18423 100644 --- a/src/Manager.php +++ b/src/Manager.php @@ -250,6 +250,27 @@ public function missingKey($namespace, $group, $key) } } + protected static function arrayToShortSyntax($data, $indent = '') + { + if (!is_array($data)) { + return var_export($data, true); + } + + $isAssoc = array_keys($data) !== range(0, count($data) - 1); + $lines = []; + $innerIndent = $indent . ' '; + + foreach ($data as $key => $value) { + $keyPart = $isAssoc ? static::arrayToShortSyntax($key) . ' => ' : ''; + $valuePart = is_array($value) + ? static::arrayToShortSyntax($value, $innerIndent) + : var_export($value, true); + $lines[] = $innerIndent . $keyPart . $valuePart; + } + + return "[\n" . implode(",\n", $lines) . "\n" . $indent . "]"; + } + public function exportTranslations($group = null, $json = false) { $group = basename($group); @@ -300,7 +321,7 @@ public function exportTranslations($group = null, $json = false) $path = $path.DIRECTORY_SEPARATOR.$locale.DIRECTORY_SEPARATOR.$group.'.php'; } - $output = "files->put($path, $output); } }