diff --git a/src/GettextPOGenerator.php b/src/GettextPOGenerator.php index 26b992c..6883654 100644 --- a/src/GettextPOGenerator.php +++ b/src/GettextPOGenerator.php @@ -180,6 +180,9 @@ private function addStringsFromJsonFiles($translations) // Load each JSON file to get source strings foreach ($this->JsonFiles() as $jsonFile) { $jsonTranslations = json_decode(file_get_contents($jsonFile), true); + if (!is_array($jsonTranslations)) { + throw new \Exception("The file '$jsonFile' is not valid JSON.'"); + } foreach ($jsonTranslations as $key => $value) { $sourceStrings[] = $key; diff --git a/src/SourceSaver.php b/src/SourceSaver.php index 4c8278e..ca3a7d3 100644 --- a/src/SourceSaver.php +++ b/src/SourceSaver.php @@ -58,15 +58,20 @@ public function call($sourceEdit, $sourceLocale) $translations = $this->applySourceEditInTranslations($translations, $sourceEdit); - $fileContent = <<<'EOT' + if (class_exists('Themsaid\Langman\Manager')) { + $manager = new \Themsaid\Langman\Manager(new Filesystem, '', [], []); + $manager->writeFile($groupFile, $translations); + } else { + $fileContent = <<<'EOT' prettyVarExport->call($translations, ['array-align' => true]); - $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 4e33ae1..11fb8ee 100644 --- a/src/TranslationSaver.php +++ b/src/TranslationSaver.php @@ -69,15 +69,20 @@ private function save($locale, $group, $translations) $this->filesystem->makeDirectory($dir, 0777, true, true); - $fileContent = <<<'EOT' + if (class_exists('Themsaid\Langman\Manager')) { + $manager = new \Themsaid\Langman\Manager(new Filesystem, '', [], []); + $manager->writeFile($dir . DIRECTORY_SEPARATOR . $group . '.php', $translations); + } else { + $fileContent = <<<'EOT' prettyVarExport->call($translations, ['array-align' => true]); - $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)