Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -300,7 +321,7 @@ public function exportTranslations($group = null, $json = false)
$path = $path.DIRECTORY_SEPARATOR.$locale.DIRECTORY_SEPARATOR.$group.'.php';
}

$output = "<?php\n\nreturn ".var_export($translations, true).';'.\PHP_EOL;
$output = "<?php\n\nreturn " . static::arrayToShortSyntax($translations) . ";\n";
$this->files->put($path, $output);
}
}
Expand Down