diff --git a/src/Manager.php b/src/Manager.php index b33530a..fea1842 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); } }