Skip to content

Commit

Permalink
fix(export): Fix export Acyion
Browse files Browse the repository at this point in the history
  • Loading branch information
alexvenga committed Jul 10, 2023
1 parent 8742bfc commit c4aba8b
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions src/Actions/ExportTranslationsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,30 @@ public function handle(): RedirectResponse
'root' => lang_path(),
]);

$translations = MoonshineLaravelTranslation::orderByRaw('`group`, `key`')->get();

$translations = $translations->mapWithKeys(function (
MoonshineLaravelTranslation $moonshineLaravelTranslation,
int $key
) {

$tempArray = [];

foreach ($moonshineLaravelTranslation->getTranslations('value') as $locale => $translation) {
$tempArray[$locale][$moonshineLaravelTranslation->group][$moonshineLaravelTranslation->key] = $translation;
$translations = MoonshineLaravelTranslation::orderByRaw('`group`, `key`')
->get()
->sortBy('group')
->groupBy('group')
->map(fn ($translationGroup) => $translationGroup
->sortBy('key')
->mapWithKeys(fn (
$translations,
$key
) => [$translations->key => $translations->getTranslations('value')]))
->toArray();

$arrayTranslations = [];

foreach ($translations as $group => $keys) {
foreach ($keys as $key => $values) {
ksort($values);
foreach ($values as $locale => $value) {
$arrayTranslations[$locale][$group][$key] = $value;
}
}
}

return $tempArray;
});

foreach ($translations as $locale => $localeData) {
foreach ($arrayTranslations as $locale => $localeData) {
foreach ($localeData as $group => $groupData) {

$groupData = Arr::undot($groupData);
Expand All @@ -55,8 +62,10 @@ public function handle(): RedirectResponse
continue;
}

$langDisk->put($locale.'/'.$group.'.php',
"<?php\n\ndeclare(strict_types=1);\n\nreturn ".$this->prettyVarExport($groupData).";\n");
$langDisk->put(
$locale.'/'.$group.'.php',
"<?php\n\ndeclare(strict_types=1);\n\nreturn ".$this->prettyVarExport($groupData).";\n"
);

}
}
Expand Down

0 comments on commit c4aba8b

Please sign in to comment.