Skip to content

Commit 1794f86

Browse files
committed
use langman for dumping translations when available
1 parent 08adb76 commit 1794f86

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
@@ -57,15 +57,20 @@ public function call($sourceEdit, $sourceLocale)
5757

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

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

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

68-
$this->filesystem->put($groupFile, $fileContent);
72+
$this->filesystem->put($groupFile, $fileContent);
73+
}
6974
}
7075
}
7176

src/TranslationSaver.php

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

6868
$this->filesystem->makeDirectory($dir, 0777, true, true);
6969

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

75-
$prettyTranslationsExport = $this->prettyVarExport->call($translations, ['array-align' => true]);
76-
$fileContent = str_replace('{{translations}}', $prettyTranslationsExport, $fileContent);
79+
$prettyTranslationsExport = $this->prettyVarExport->call($translations, ['array-align' => true]);
80+
$fileContent = str_replace('{{translations}}', $prettyTranslationsExport, $fileContent);
7781

78-
$this->filesystem->put($dir . DIRECTORY_SEPARATOR . $group . '.php', $fileContent);
82+
$this->filesystem->put($dir . DIRECTORY_SEPARATOR . $group . '.php', $fileContent);
83+
}
7984
}
8085

8186
private function localePath($locale)

0 commit comments

Comments
 (0)