From c62292f0e53aaadba59b9cbd86afd86b4a576375 Mon Sep 17 00:00:00 2001
From: Lukas Kahwe Smith <smith@pooteeweet.org>
Date: Mon, 2 Sep 2019 17:56:12 +0200
Subject: [PATCH] use https://github.com/liip/laravel-langman for dumping the
 file when available

---
 src/SourceSaver.php      | 19 +++++++++++--------
 src/TranslationSaver.php | 17 ++++++++++-------
 2 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/src/SourceSaver.php b/src/SourceSaver.php
index febf5bf..66e3a3e 100644
--- a/src/SourceSaver.php
+++ b/src/SourceSaver.php
@@ -54,20 +54,23 @@ public function call($sourceEdit, $sourceLocale)
 
         if ($this->filesystem->exists($groupFile)) {
             $translations = $this->filesystem->getRequire($groupFile);
-dd($translations);
-            $translations = $this->applySourceEditInTranslations($translations, $sourceEdit);
 
-            $fileContent = <<<'EOT'
-<?php 
+            $translations = $this->applySourceEditInTranslations($translations, $sourceEdit);
 
+            if (class_exists('Themsaid\Langman\Manager')) {
+                $manager = new \Themsaid\Langman\Manager(new Filesystem, '', []);
+                $manager->writeFile($groupFile, $translations);
+            } else {
+                $fileContent = <<<'EOT'
+<?php
 return {{translations}};
 EOT;
-            $fileContent = rtrim($fileContent);
 
-            $prettyTranslationsExport = $this->prettyVarExport->call($translations);
-            $fileContent  = str_replace('{{translations}}', $prettyTranslationsExport, $fileContent);
+                $prettyTranslationsExport = $this->prettyVarExport->call($translations, ['array-align' => true]);
+                $fileContent = str_replace('{{translations}}', $prettyTranslationsExport, $fileContent);
 
-            $this->filesystem->put($groupFile, $fileContent);
+                $this->filesystem->put($groupFile, $fileContent);
+            }
         }
     }
 
diff --git a/src/TranslationSaver.php b/src/TranslationSaver.php
index c4193c1..2bd1542 100644
--- a/src/TranslationSaver.php
+++ b/src/TranslationSaver.php
@@ -67,17 +67,20 @@ private function save($locale, $group, $translations)
 
         $this->filesystem->makeDirectory($dir, 0777, true, true);
 
-        $fileContent = <<<'EOT'
-<?php 
-
+        if (class_exists('Themsaid\Langman\Manager')) {
+            $manager = new \Themsaid\Langman\Manager(new Filesystem, '', []);
+            $manager->writeFile($dir . DIRECTORY_SEPARATOR . $group . '.php', $translations);
+        } else {
+            $fileContent = <<<'EOT'
+<?php
 return {{translations}};
 EOT;
-        $fileContent = rtrim($fileContent);
 
-        $prettyTranslationsExport = $this->prettyVarExport->call($translations);
-        $fileContent = str_replace('{{translations}}', $prettyTranslationsExport, $fileContent);
+            $prettyTranslationsExport = $this->prettyVarExport->call($translations, ['array-align' => true]);
+            $fileContent = str_replace('{{translations}}', $prettyTranslationsExport, $fileContent);
 
-        $this->filesystem->put($dir . DIRECTORY_SEPARATOR . $group . '.php', $fileContent);
+            $this->filesystem->put($dir . DIRECTORY_SEPARATOR . $group . '.php', $fileContent);
+        }
     }
 
     private function localePath($locale)