From 719f4893ada2613e4d9f9bb894da50d7f5d16d85 Mon Sep 17 00:00:00 2001 From: alexvenga Date: Fri, 7 Jul 2023 22:24:58 +0300 Subject: [PATCH] fix(new-structure): Drop custom ordering/Fix dots Drop custom ordering for translations Fix dot-notation --- ...n_moonshine_laravel_translations_table.php | 27 +++++++++++++++++++ src/Actions/ExportTranslationsAction.php | 4 ++- src/Actions/ImportTranslationsAction.php | 5 ---- src/Models/MoonshineLaravelTranslation.php | 1 - 4 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 database/migrations/2023_07_08_140130_drop_list_order_in_moonshine_laravel_translations_table.php diff --git a/database/migrations/2023_07_08_140130_drop_list_order_in_moonshine_laravel_translations_table.php b/database/migrations/2023_07_08_140130_drop_list_order_in_moonshine_laravel_translations_table.php new file mode 100644 index 0000000..8a87d0d --- /dev/null +++ b/database/migrations/2023_07_08_140130_drop_list_order_in_moonshine_laravel_translations_table.php @@ -0,0 +1,27 @@ +dropColumn('list_order'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('moonshine_laravel_translations', function (Blueprint $table) { + $table->unsignedSmallInteger('list_order')->default(65535)->after('group'); + }); + } +}; diff --git a/src/Actions/ExportTranslationsAction.php b/src/Actions/ExportTranslationsAction.php index b07f181..1556e7c 100644 --- a/src/Actions/ExportTranslationsAction.php +++ b/src/Actions/ExportTranslationsAction.php @@ -24,7 +24,7 @@ public function handle(): RedirectResponse 'root' => lang_path(), ]); - $translations = MoonshineLaravelTranslation::orderBy('list_order')->get(); + $translations = MoonshineLaravelTranslation::orderBy('group, key')->get(); $translations = $translations->mapWithKeys(function ( MoonshineLaravelTranslation $moonshineLaravelTranslation, @@ -43,6 +43,8 @@ public function handle(): RedirectResponse foreach ($translations as $locale => $localeData) { foreach ($localeData as $group => $groupData) { + $groupData = Arr::undot($groupData); + if ($group == 'json') { $langDisk->put( diff --git a/src/Actions/ImportTranslationsAction.php b/src/Actions/ImportTranslationsAction.php index 9f85a54..5fcc409 100644 --- a/src/Actions/ImportTranslationsAction.php +++ b/src/Actions/ImportTranslationsAction.php @@ -45,7 +45,6 @@ public function handle(): RedirectResponse foreach ($arrayTranslations as $key => $value) { $this->updateOrCreateTranslation([ 'group' => $groupName, - 'list_order' => $i, 'key' => $key, 'locale' => $locale, 'value' => $value, @@ -61,16 +60,13 @@ public function handle(): RedirectResponse $groupName = $fileName->replaceFirst($locale.'/', '')->replaceLast('.php', ''); $arrayTranslations = include lang_path($fileName->toString()); $arrayTranslations = Arr::dot($arrayTranslations); - $i = 0; foreach ($arrayTranslations as $key => $value) { $this->updateOrCreateTranslation([ 'group' => $groupName, - 'list_order' => $i, 'key' => $key, 'locale' => $locale, 'value' => $value, ]); - $i++; } return; @@ -109,7 +105,6 @@ protected function updateOrCreateTranslation(array $data) 'group' => $data['group'], 'key' => $data['key'], ], [ - 'list_order' => $data['list_order'] ?? 0, 'is_changed' => false, ]); diff --git a/src/Models/MoonshineLaravelTranslation.php b/src/Models/MoonshineLaravelTranslation.php index e3a2c1b..87845a8 100644 --- a/src/Models/MoonshineLaravelTranslation.php +++ b/src/Models/MoonshineLaravelTranslation.php @@ -17,7 +17,6 @@ class MoonshineLaravelTranslation extends Model protected $fillable = [ 'group', - 'list_order', 'key', 'locale', 'value',