Skip to content

Commit c62292f

Browse files
committed
use https://github.com/liip/laravel-langman for dumping the file when
available
1 parent 29d2a23 commit c62292f

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

src/SourceSaver.php

+11-8
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,23 @@ public function call($sourceEdit, $sourceLocale)
5454

5555
if ($this->filesystem->exists($groupFile)) {
5656
$translations = $this->filesystem->getRequire($groupFile);
57-
dd($translations);
58-
$translations = $this->applySourceEditInTranslations($translations, $sourceEdit);
5957

60-
$fileContent = <<<'EOT'
61-
<?php
58+
$translations = $this->applySourceEditInTranslations($translations, $sourceEdit);
6259

60+
if (class_exists('Themsaid\Langman\Manager')) {
61+
$manager = new \Themsaid\Langman\Manager(new Filesystem, '', []);
62+
$manager->writeFile($groupFile, $translations);
63+
} else {
64+
$fileContent = <<<'EOT'
65+
<?php
6366
return {{translations}};
6467
EOT;
65-
$fileContent = rtrim($fileContent);
6668

67-
$prettyTranslationsExport = $this->prettyVarExport->call($translations);
68-
$fileContent = str_replace('{{translations}}', $prettyTranslationsExport, $fileContent);
69+
$prettyTranslationsExport = $this->prettyVarExport->call($translations, ['array-align' => true]);
70+
$fileContent = str_replace('{{translations}}', $prettyTranslationsExport, $fileContent);
6971

70-
$this->filesystem->put($groupFile, $fileContent);
72+
$this->filesystem->put($groupFile, $fileContent);
73+
}
7174
}
7275
}
7376

src/TranslationSaver.php

+10-7
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,20 @@ private function save($locale, $group, $translations)
6767

6868
$this->filesystem->makeDirectory($dir, 0777, true, true);
6969

70-
$fileContent = <<<'EOT'
71-
<?php
72-
70+
if (class_exists('Themsaid\Langman\Manager')) {
71+
$manager = new \Themsaid\Langman\Manager(new Filesystem, '', []);
72+
$manager->writeFile($dir . DIRECTORY_SEPARATOR . $group . '.php', $translations);
73+
} else {
74+
$fileContent = <<<'EOT'
75+
<?php
7376
return {{translations}};
7477
EOT;
75-
$fileContent = rtrim($fileContent);
7678

77-
$prettyTranslationsExport = $this->prettyVarExport->call($translations);
78-
$fileContent = str_replace('{{translations}}', $prettyTranslationsExport, $fileContent);
79+
$prettyTranslationsExport = $this->prettyVarExport->call($translations, ['array-align' => true]);
80+
$fileContent = str_replace('{{translations}}', $prettyTranslationsExport, $fileContent);
7981

80-
$this->filesystem->put($dir . DIRECTORY_SEPARATOR . $group . '.php', $fileContent);
82+
$this->filesystem->put($dir . DIRECTORY_SEPARATOR . $group . '.php', $fileContent);
83+
}
8184
}
8285

8386
private function localePath($locale)

0 commit comments

Comments
 (0)