Files
2026-02-18 01:31:41 +01:00

7.3 KiB

phase, plan, type, wave, depends_on, files_modified, autonomous, must_haves
phase plan type wave depends_on files_modified autonomous must_haves
15-locale-detection-routing 01 execute 1
plugins/golem15/quotify/Plugin.php
plugins/golem15/translate/routes.php
true
truths artifacts key_links
Manual locale selection via LocalePicker sets 1-year cookie
URL prefix visit (/pl/, /de/) sets manual selection cookie
Logged-in user's locale switch updates their DB preference
Browser detection skipped when manual selection cookie exists
path provides contains
plugins/golem15/quotify/Plugin.php LocalePicker extension with cookie and DB sync LocalePicker::extend
path provides contains
plugins/golem15/translate/routes.php Cookie setting on URL prefix detection locale_manually_set
from to via pattern
LocalePicker::onSwitchLocale Cookie::queue component extension in Plugin.php boot() Cookie::queue.*locale_manually_set
from to via pattern
LocalePicker::onSwitchLocale User::preferred_locale Auth::getUser()->save() preferred_locale.*=.*locale
Implement core locale preference infrastructure: cookie setting for manual selections and database sync for logged-in users.

Purpose: Fix the identified gap where locale_manually_set cookie is read by middleware but never written, and ensure logged-in users' preferences persist to database. Output: LocalePicker extension in Quotify Plugin.php, updated routes.php with cookie setting on URL prefix

<execution_context> @/home/jin/.claude/get-shit-done/workflows/execute-plan.md @/home/jin/.claude/get-shit-done/templates/summary.md </execution_context>

@.planning/PROJECT.md @.planning/ROADMAP.md @.planning/phases/15-locale-detection-routing/15-CONTEXT.md @.planning/phases/15-locale-detection-routing/15-RESEARCH.md

@plugins/golem15/quotify/Plugin.php @plugins/golem15/translate/routes.php @plugins/golem15/translate/components/LocalePicker.php @plugins/golem15/translate/classes/LocaleMiddleware.php

Task 1: Extend LocalePicker to set cookie and sync user preference plugins/golem15/quotify/Plugin.php In the boot() method of Quotify Plugin.php, add an extension to LocalePicker component:
// Extend LocalePicker to set manual selection cookie and sync user preference
\Golem15\Translate\Components\LocalePicker::extend(function($component) {
    $component->bindEvent('component.beforeRunAjaxHandler', function($handler) use ($component) {
        if ($handler === 'onSwitchLocale') {
            $locale = post('locale');

            // Validate locale before proceeding
            if (!$locale || !\Golem15\Translate\Models\Locale::isValid($locale)) {
                return;
            }

            // Set manual selection cookie (1 year = 525600 minutes)
            \Cookie::queue(
                \Config::get('golem15.translate::browserDetection.manualSelectionCookie', 'locale_manually_set'),
                '1',
                \Config::get('golem15.translate::browserDetection.manualSelectionExpiry', 525600)
            );

            // Update user preference in DB if logged in
            if (\Auth::check()) {
                $user = \Auth::getUser();
                $user->preferred_locale = $locale;
                $user->save();
            }
        }
    });
});

Add this after the existing extensions in boot() (after User model extensions). Import Cookie facade at top if not present.

Do NOT modify the core LocalePicker.php in the Translate plugin - use WinterCMS extension pattern. Check Plugin.php contains LocalePicker::extend with Cookie::queue and Auth::getUser()->preferred_locale logic LocalePicker component extended to set cookie and sync DB preference on locale switch

Task 2: Set cookie on URL prefix detection in routes.php plugins/golem15/translate/routes.php In routes.php, after the locale is detected from URL prefix (after line 23 where `$translator->loadLocaleFromRequest()` succeeds), add cookie setting:
// After: if (!$translator->loadLocaleFromRequest() || (!$locale = $translator->getLocale()))
// Inside the check where locale WAS loaded from request:

// Set manual selection cookie when URL has locale prefix
// This prevents browser detection from overriding explicit URL visits
\Cookie::queue(
    \Config::get('golem15.translate::browserDetection.manualSelectionCookie', 'locale_manually_set'),
    '1',
    \Config::get('golem15.translate::browserDetection.manualSelectionExpiry', 525600)
);

The existing code structure is:

if (
    !$translator->isConfigured() ||
    !$translator->loadLocaleFromRequest() ||  // This returns true when URL has prefix
    (!$locale = $translator->getLocale())
) {
    return;
}
// If we get here, locale WAS loaded from URL prefix
// ADD COOKIE SETTING HERE before route registration

Cookie import should use full namespace \Cookie::queue() to avoid import issues. Check routes.php contains Cookie::queue call after loadLocaleFromRequest succeeds URL prefix visits (/pl/, /de/) set manual selection cookie to prevent browser detection override

Task 3: Verify middleware reads the cookie correctly plugins/golem15/translate/classes/LocaleMiddleware.php Verify (read-only) that LocaleMiddleware::hasManualLocaleSelection() correctly reads the cookie:
  1. Check it reads from config: golem15.translate::browserDetection.manualSelectionCookie
  2. Check it returns true when cookie is present
  3. Check it's called in the locale detection cascade (Priority 4)

This is a verification task - the middleware already has this logic from the research. Just confirm it works with our cookie name.

If any issues found, log them. The middleware should NOT be modified unless absolutely necessary (it's a shared plugin). Read LocaleMiddleware.php and confirm hasManualLocaleSelection() checks for the correct cookie name Confirmed middleware reads locale_manually_set cookie and skips browser detection when present

1. Code review: Plugin.php has LocalePicker::extend with cookie + DB sync 2. Code review: routes.php sets cookie after URL prefix detection 3. Code review: LocaleMiddleware reads same cookie name 4. Manual test: Switch language via picker, check cookie is set (DevTools > Application > Cookies) 5. Manual test: Visit /pl/jobs, check cookie is set 6. Manual test: Clear cookies, visit site, browser detection should work 7. Manual test: Set language via picker, browser detection should be skipped on next visit

<success_criteria>

  • LocalePicker::onSwitchLocale sets locale_manually_set cookie (1 year expiry)
  • LocalePicker::onSwitchLocale updates User::preferred_locale for logged-in users
  • URL prefix visits (/pl/, /de/) set locale_manually_set cookie
  • LocaleMiddleware skips browser detection when cookie present
  • No modifications to core Translate plugin classes (only routes.php touched) </success_criteria>
After completion, create `.planning/phases/15-locale-detection-routing/15-01-SUMMARY.md`