Add multilingual support to labor categories (RO/RU/EN)
- Migration: adds name_ro, name_ru, name_en columns; copies name→name_ro; seeds RU and EN translations for all 11 default categories - LaborCategory: label() returns localized name, optionsForSelect() keyed by canonical name (stored in labors.category) with localized label - LaborCategoryResource: 3-column form with RO/RU/EN inputs; table shows all three columns side by side - LaborResource: category select and filter use optionsForSelect() Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('labor_categories', function (Blueprint $table) {
|
||||
$table->string('name_ro')->nullable()->after('name');
|
||||
$table->string('name_ru')->nullable()->after('name_ro');
|
||||
$table->string('name_en')->nullable()->after('name_ru');
|
||||
});
|
||||
|
||||
// Copy existing name → name_ro
|
||||
DB::table('labor_categories')->update(['name_ro' => DB::raw('`name`')]);
|
||||
|
||||
// Seed Russian and English for the default categories
|
||||
$translations = [
|
||||
'Motor' => ['ru' => 'Двигатель', 'en' => 'Engine'],
|
||||
'Frâne' => ['ru' => 'Тормоза', 'en' => 'Brakes'],
|
||||
'Suspensie' => ['ru' => 'Подвеска', 'en' => 'Suspension'],
|
||||
'Anvelope' => ['ru' => 'Шины', 'en' => 'Tires'],
|
||||
'ITP' => ['ru' => 'Техосмотр', 'en' => 'Inspection'],
|
||||
'Cutie viteze' => ['ru' => 'Коробка передач', 'en' => 'Gearbox'],
|
||||
'Caroserie' => ['ru' => 'Кузов', 'en' => 'Bodywork'],
|
||||
'Electrică' => ['ru' => 'Электрика', 'en' => 'Electrical'],
|
||||
'Climatizare' => ['ru' => 'Климат', 'en' => 'AC / Climate'],
|
||||
'Eșapament' => ['ru' => 'Выхлоп', 'en' => 'Exhaust'],
|
||||
'Altele' => ['ru' => 'Прочее', 'en' => 'Other'],
|
||||
];
|
||||
|
||||
foreach ($translations as $name => $t) {
|
||||
DB::table('labor_categories')
|
||||
->where('name', $name)
|
||||
->update(['name_ru' => $t['ru'], 'name_en' => $t['en']]);
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('labor_categories', function (Blueprint $table) {
|
||||
$table->dropColumn(['name_ro', 'name_ru', 'name_en']);
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user