Skip to content

Commit 344862d

Browse files
committed
optionally use themsaid/langman to generate the PHP translation files
1 parent 4779bcc commit 344862d

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

src/SourceSaver.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,20 @@ public function call($sourceEdit, $sourceLocale)
5858

5959
$translations = $this->applySourceEditInTranslations($translations, $sourceEdit);
6060

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

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

69-
$this->filesystem->put($groupFile, $fileContent);
73+
$this->filesystem->put($groupFile, $fileContent);
74+
}
7075
}
7176
}
7277

src/TranslationSaver.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,20 @@ private function save($locale, $group, $translations)
6969

7070
$this->filesystem->makeDirectory($dir, 0777, true, true);
7171

72-
$fileContent = <<<'EOT'
72+
if (class_exists('Themsaid\Langman\Manager')) {
73+
$manager = new \Themsaid\Langman\Manager(new Filesystem, '', [], []);
74+
$manager->writeFile($dir . DIRECTORY_SEPARATOR . $group . '.php', $translations);
75+
} else {
76+
$fileContent = <<<'EOT'
7377
<?php
7478
return {{translations}};
7579
EOT;
7680

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

80-
$this->filesystem->put($dir . DIRECTORY_SEPARATOR . $group . '.php', $fileContent);
84+
$this->filesystem->put($dir . DIRECTORY_SEPARATOR . $group . '.php', $fileContent);
85+
}
8186
}
8287

8388
private function localePath($locale)

0 commit comments

Comments
 (0)