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" + ); } }