Skip to content

Commit

Permalink
fix(new-structure): Drop custom ordering/Fix dots
Browse files Browse the repository at this point in the history
Drop custom ordering for translations
Fix dot-notation
  • Loading branch information
alexvenga committed Jul 7, 2023
1 parent 8e9a8a1 commit 719f489
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('moonshine_laravel_translations', function (Blueprint $table) {
$table->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');
});
}
};
4 changes: 3 additions & 1 deletion src/Actions/ExportTranslationsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand Down
5 changes: 0 additions & 5 deletions src/Actions/ImportTranslationsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -109,7 +105,6 @@ protected function updateOrCreateTranslation(array $data)
'group' => $data['group'],
'key' => $data['key'],
], [
'list_order' => $data['list_order'] ?? 0,
'is_changed' => false,
]);

Expand Down
1 change: 0 additions & 1 deletion src/Models/MoonshineLaravelTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class MoonshineLaravelTranslation extends Model

protected $fillable = [
'group',
'list_order',
'key',
'locale',
'value',
Expand Down

0 comments on commit 719f489

Please sign in to comment.