From c4aba8b622f8219f36aa3197e55796130848db4c Mon Sep 17 00:00:00 2001 From: alexvenga Date: Mon, 10 Jul 2023 20:25:59 +0300 Subject: [PATCH] fix(export): Fix export Acyion --- src/Actions/ExportTranslationsAction.php | 43 ++++++++++++++---------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/src/Actions/ExportTranslationsAction.php b/src/Actions/ExportTranslationsAction.php index d63d9f5..c6b12fc 100644 --- a/src/Actions/ExportTranslationsAction.php +++ b/src/Actions/ExportTranslationsAction.php @@ -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); @@ -55,8 +62,10 @@ public function handle(): RedirectResponse continue; } - $langDisk->put($locale.'/'.$group.'.php', - "prettyVarExport($groupData).";\n"); + $langDisk->put( + $locale.'/'.$group.'.php', + "prettyVarExport($groupData).";\n" + ); } }