185 lines
7.3 KiB
Markdown
185 lines
7.3 KiB
Markdown
---
|
|
phase: 15-locale-detection-routing
|
|
plan: 01
|
|
type: execute
|
|
wave: 1
|
|
depends_on: []
|
|
files_modified:
|
|
- plugins/golem15/quotify/Plugin.php
|
|
- plugins/golem15/translate/routes.php
|
|
autonomous: true
|
|
|
|
must_haves:
|
|
truths:
|
|
- "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"
|
|
artifacts:
|
|
- path: "plugins/golem15/quotify/Plugin.php"
|
|
provides: "LocalePicker extension with cookie and DB sync"
|
|
contains: "LocalePicker::extend"
|
|
- path: "plugins/golem15/translate/routes.php"
|
|
provides: "Cookie setting on URL prefix detection"
|
|
contains: "locale_manually_set"
|
|
key_links:
|
|
- from: "LocalePicker::onSwitchLocale"
|
|
to: "Cookie::queue"
|
|
via: "component extension in Plugin.php boot()"
|
|
pattern: "Cookie::queue.*locale_manually_set"
|
|
- from: "LocalePicker::onSwitchLocale"
|
|
to: "User::preferred_locale"
|
|
via: "Auth::getUser()->save()"
|
|
pattern: "preferred_locale.*=.*locale"
|
|
---
|
|
|
|
<objective>
|
|
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
|
|
</objective>
|
|
|
|
<execution_context>
|
|
@/home/jin/.claude/get-shit-done/workflows/execute-plan.md
|
|
@/home/jin/.claude/get-shit-done/templates/summary.md
|
|
</execution_context>
|
|
|
|
<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
|
|
</context>
|
|
|
|
<tasks>
|
|
|
|
<task type="auto">
|
|
<name>Task 1: Extend LocalePicker to set cookie and sync user preference</name>
|
|
<files>plugins/golem15/quotify/Plugin.php</files>
|
|
<action>
|
|
In the boot() method of Quotify Plugin.php, add an extension to LocalePicker component:
|
|
|
|
```php
|
|
// 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.
|
|
</action>
|
|
<verify>Check Plugin.php contains LocalePicker::extend with Cookie::queue and Auth::getUser()->preferred_locale logic</verify>
|
|
<done>LocalePicker component extended to set cookie and sync DB preference on locale switch</done>
|
|
</task>
|
|
|
|
<task type="auto">
|
|
<name>Task 2: Set cookie on URL prefix detection in routes.php</name>
|
|
<files>plugins/golem15/translate/routes.php</files>
|
|
<action>
|
|
In routes.php, after the locale is detected from URL prefix (after line 23 where `$translator->loadLocaleFromRequest()` succeeds), add cookie setting:
|
|
|
|
```php
|
|
// 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:
|
|
```php
|
|
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.
|
|
</action>
|
|
<verify>Check routes.php contains Cookie::queue call after loadLocaleFromRequest succeeds</verify>
|
|
<done>URL prefix visits (/pl/, /de/) set manual selection cookie to prevent browser detection override</done>
|
|
</task>
|
|
|
|
<task type="auto">
|
|
<name>Task 3: Verify middleware reads the cookie correctly</name>
|
|
<files>plugins/golem15/translate/classes/LocaleMiddleware.php</files>
|
|
<action>
|
|
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).
|
|
</action>
|
|
<verify>Read LocaleMiddleware.php and confirm hasManualLocaleSelection() checks for the correct cookie name</verify>
|
|
<done>Confirmed middleware reads locale_manually_set cookie and skips browser detection when present</done>
|
|
</task>
|
|
|
|
</tasks>
|
|
|
|
<verification>
|
|
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
|
|
</verification>
|
|
|
|
<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>
|
|
|
|
<output>
|
|
After completion, create `.planning/phases/15-locale-detection-routing/15-01-SUMMARY.md`
|
|
</output>
|