Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions src/GettextPOGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 9 additions & 4 deletions src/SourceSaver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
<?php
return {{translations}};
EOT;

$prettyTranslationsExport = $this->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);
}
}
}

Expand Down
13 changes: 9 additions & 4 deletions src/TranslationSaver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
<?php
return {{translations}};
EOT;

$prettyTranslationsExport = $this->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)
Expand Down