Skip to content

Commit

Permalink
optionally use themsaid/langman to generate the PHP translation files
Browse files Browse the repository at this point in the history
  • Loading branch information
lsmith77 committed Oct 10, 2019
1 parent 4779bcc commit 344862d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
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

0 comments on commit 344862d

Please sign in to comment.