fix: language switcher stuck in French on store dashboard
Some checks failed
Some checks failed
Three compounding bugs prevented language switching on the store dashboard: - Cookie missing path="/", scoping it to the API endpoint path only - STORE frontend resolution chain ignored the cookie entirely - Store header used inline x-data with wrong language names instead of shared languageSelector() Also updates architecture doc with correct per-frontend resolution priorities, cookie name, API endpoint path, and file references. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -44,18 +44,20 @@ language = "lux" # ❌ Use "lb"
|
||||
|
||||
## Language Context Flow
|
||||
|
||||
### Resolution Priority
|
||||
### Resolution Priority (per Frontend Type)
|
||||
|
||||
Language is resolved in this order (highest to lowest priority):
|
||||
Language resolution varies by frontend type. Each chain is evaluated top-to-bottom, first match wins:
|
||||
|
||||
1. **URL parameter** (`?lang=fr`)
|
||||
2. **Cookie** (`orion_language`)
|
||||
3. **User preference** (database: `preferred_language`)
|
||||
4. **Store default** (database: `storefront_language` or `dashboard_language`)
|
||||
5. **Accept-Language header** (browser)
|
||||
6. **Platform default** (`fr`)
|
||||
| Frontend | Priority (highest → lowest) |
|
||||
|----------|----------------------------|
|
||||
| **ADMIN** | User `preferred_language` → `"en"` |
|
||||
| **STORE** | Cookie (`lang`) → User `preferred_language` → Store `dashboard_language` → `"fr"` |
|
||||
| **STOREFRONT** | Customer `preferred_language` → Cookie (`lang`) → Store `storefront_language` → Browser `Accept-Language` → `"fr"` |
|
||||
| **PLATFORM** | Cookie (`lang`) → Browser `Accept-Language` → `"fr"` |
|
||||
|
||||
### Store Dashboard vs Storefront
|
||||
The **cookie** (`lang`) is set by the language switcher UI via `POST /api/v1/platform/language/set` and represents the user's most recent explicit language choice. It takes priority over database preferences because it reflects an immediate UI action.
|
||||
|
||||
### Database Fields
|
||||
|
||||
| Context | Language Source | Database Field |
|
||||
|---------|-----------------|----------------|
|
||||
@@ -210,7 +212,7 @@ function languageSelector(currentLang, enabledLanguages) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const response = await fetch('/api/v1/language/set', {
|
||||
const response = await fetch('/api/v1/platform/language/set', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ language: lang })
|
||||
@@ -270,11 +272,12 @@ async def set_language(request: LanguageSetRequest, response: Response):
|
||||
raise HTTPException(status_code=400, detail="Unsupported language")
|
||||
|
||||
response.set_cookie(
|
||||
key="orion_language",
|
||||
key="lang",
|
||||
value=request.language,
|
||||
max_age=365 * 24 * 60 * 60, # 1 year
|
||||
httponly=True,
|
||||
samesite="lax"
|
||||
httponly=False, # Accessible to JavaScript
|
||||
samesite="lax",
|
||||
path="/", # Must be site-wide
|
||||
)
|
||||
return {"success": True, "language": request.language}
|
||||
```
|
||||
@@ -379,16 +382,16 @@ languageFlags: {
|
||||
|
||||
```javascript
|
||||
// ✅ GOOD: Correct endpoint
|
||||
fetch('/api/v1/language/set', {
|
||||
fetch('/api/v1/platform/language/set', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ language: lang })
|
||||
});
|
||||
|
||||
// ❌ BAD: Wrong endpoint or method
|
||||
fetch('/api/language/set', ...); // ❌ Missing /v1
|
||||
fetch('/api/v1/language', ...); // ❌ Missing /set
|
||||
fetch('/api/v1/language/set', { method: 'GET' }); // ❌ Should be POST
|
||||
fetch('/api/v1/language/set', ...); // ❌ Missing /platform
|
||||
fetch('/api/v1/platform/language', ...); // ❌ Missing /set
|
||||
fetch('/api/v1/platform/language/set', { method: 'GET' }); // ❌ Should be POST
|
||||
```
|
||||
|
||||
---
|
||||
@@ -467,7 +470,7 @@ static/locales/
|
||||
- [ ] Provides default values for both parameters
|
||||
- [ ] Uses native language names (Français, Deutsch, Lëtzebuergesch)
|
||||
- [ ] Uses correct flag codes (en→gb, fr→fr, de→de, lb→lu)
|
||||
- [ ] Calls `/api/v1/language/set` with POST method
|
||||
- [ ] Calls `/api/v1/platform/language/set` with POST method
|
||||
- [ ] Reloads page after successful language change
|
||||
- [ ] Hides selector if only one language enabled (storefront)
|
||||
- [ ] Shows all languages (store dashboard)
|
||||
@@ -491,7 +494,7 @@ static/locales/
|
||||
| `static/store/js/init-alpine.js` | JS | `languageSelector()` function |
|
||||
| `app/templates/shop/base.html` | Template | Storefront language selector |
|
||||
| `app/templates/store/partials/header.html` | Template | Dashboard language selector |
|
||||
| `app/api/v1/shared/language.py` | API | Language endpoints |
|
||||
| `app/modules/core/routes/api/platform.py` | API | Language endpoints (`/api/v1/platform/language/*`) |
|
||||
| `middleware/language.py` | Middleware | Language detection |
|
||||
| `static/locales/*.json` | JSON | Translation files |
|
||||
|
||||
|
||||
Reference in New Issue
Block a user