# Language Migration Quick Checklist

Use this checklist when migrating the next 2 sites.

## Pre-Migration

- [ ] Backup database
- [ ] Note current hardcoded languages in use
- [ ] Check which languages are actually used in posts table

## Step 1: Create Model & Migration

- [ ] Run: `php artisan make:model Language -m`
- [ ] Update migration with all fields (code, name, flag, gtranslate_code, is_enabled, sort_order)
- [ ] Update Language model with fillable, casts, and scopes

## Step 2: Create Filament Resource

- [ ] Run: `php artisan make:filament-resource Language --generate`
- [ ] Update LanguageResource:
  - [ ] Set navigation icon, label, group
  - [ ] Configure form fields (NO flag field)
  - [ ] Configure table columns (NO flag column)
  - [ ] Set default sort

## Step 3: Create Seeder

- [ ] Run: `php artisan make:seeder LanguageSeeder`
- [ ] Add base languages (de, no, en, es, fr, it, pt, fi)
- [ ] Add logic to detect languages from posts
- [ ] Set only de and no as enabled by default

## Step 4: Update PostController

- [ ] Add `use App\Models\Language;`
- [ ] Replace hardcoded arrays in `getCasinoPosts()`
- [ ] Replace hardcoded arrays in `getCombinedReviews()`
- [ ] Replace hardcoded arrays in `fetchUpdatedSections()`
- [ ] Replace hardcoded arrays in `show()`
- [ ] Update default language logic

## Step 5: Update PostResource

- [ ] Remove `$supportedLanguages` static array
- [ ] Add `getSupportedLanguages()` method
- [ ] Replace all `self::$supportedLanguages` with `self::getSupportedLanguages()`
- [ ] Update language MultiSelect field
- [ ] Update localized sections (deposit, withdrawal, bonus)
- [ ] Update post ordering section
- [ ] Update language filter in table
- [ ] Update order display method

## Step 6: Update Language Switcher Component

- [ ] Replace hardcoded languages array
- [ ] Add database fetch logic
- [ ] Update current language detection
- [ ] Add GTranslate mapping JSON
- [ ] Add `data-gt-mapping` attribute to component HTML

## Step 7: Update app.js

- [ ] Replace hardcoded langMap object
- [ ] Add logic to read from data attribute
- [ ] Add fallback handling

## Step 8: Update Other Files

- [ ] Update `LandingPageQueryService.php`
- [ ] Update `LandingPageController.php`

## Step 9: Set Admin Locale

- [ ] Update `AppServiceProvider.php` boot() method
- [ ] Add Filament route detection
- [ ] Set English for admin, German for frontend

## Step 10: Run Migration & Seeder

- [ ] Run migration: `php artisan migrate --path=database/migrations/...`
- [ ] Run seeder: `php artisan db:seed --class=LanguageSeeder`

## Post-Migration Testing

- [ ] Check admin panel → Settings → Languages exists
- [ ] Create a test language
- [ ] Enable/disable a language
- [ ] Check language switcher on frontend
- [ ] Test post filtering by language
- [ ] Verify admin is in English
- [ ] Verify frontend is in German
- [ ] Check GTranslate integration works

## Files to Verify

**Created:**
- [ ] `app/Models/Language.php`
- [ ] `database/migrations/..._create_languages_table.php`
- [ ] `app/Filament/Resources/LanguageResource.php`
- [ ] `database/seeders/LanguageSeeder.php`

**Modified:**
- [ ] `app/Http/Controllers/PostController.php`
- [ ] `app/Filament/Resources/PostResource.php`
- [ ] `resources/views/components/pirate-language-switcher.blade.php`
- [ ] `resources/js/app.js`
- [ ] `app/Services/LandingPageQueryService.php`
- [ ] `app/Http/Controllers/LandingPageController.php`
- [ ] `app/Providers/AppServiceProvider.php`

## Common Issues

- **Migration fails:** Check if languages table already exists
- **Seeder fails:** Check database connection
- **Admin still German:** Clear cache: `php artisan config:clear`
- **Switcher empty:** Check if languages are enabled in database
- **GTranslate not working:** Verify gtranslate_code values in database

---

**Reference:** See `LANGUAGE_MIGRATION_GUIDE.md` for detailed code examples.
