- Add database fields for language preferences: - Vendor: dashboard_language, storefront_language, storefront_languages - User: preferred_language - Customer: preferred_language - Add language middleware for request-level language detection: - Cookie-based persistence - Browser Accept-Language fallback - Vendor storefront language constraints - Add language API endpoints (/api/v1/language/*): - POST /set - Set language preference - GET /current - Get current language info - GET /list - List available languages - DELETE /clear - Clear preference - Add i18n utilities (app/utils/i18n.py): - JSON-based translation loading - Jinja2 template integration - Language resolution helpers - Add reusable language selector macros for templates - Add languageSelector() Alpine.js component - Add translation files (en, fr, de, lb) in static/locales/ - Add architecture rules documentation for language implementation - Update marketplace-product-detail.js to use native language names 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
182 lines
10 KiB
HTML
182 lines
10 KiB
HTML
{# app/templates/vendor/partials/header.html #}
|
|
<header class="z-10 py-4 bg-white shadow-md dark:bg-gray-800">
|
|
<div class="container flex items-center justify-between h-full px-6 mx-auto text-purple-600 dark:text-purple-300">
|
|
<!-- Mobile hamburger -->
|
|
<button class="p-1 mr-5 -ml-1 rounded-md md:hidden focus:outline-none focus:shadow-outline-purple"
|
|
@click="toggleSideMenu"
|
|
aria-label="Menu">
|
|
<span x-html="$icon('menu', 'w-6 h-6')"></span>
|
|
</button>
|
|
|
|
<!-- Search input -->
|
|
<div class="flex justify-center flex-1 lg:mr-32">
|
|
<div class="relative w-full max-w-xl mr-6 focus-within:text-purple-500">
|
|
<div class="absolute inset-y-0 flex items-center pl-2">
|
|
<span x-html="$icon('search', 'w-4 h-4')"></span>
|
|
</div>
|
|
<input class="w-full pl-8 pr-2 text-sm text-gray-700 placeholder-gray-600 bg-gray-100 border-0 rounded-md dark:placeholder-gray-500 dark:focus:shadow-outline-gray dark:focus:placeholder-gray-600 dark:bg-gray-700 dark:text-gray-200 focus:placeholder-gray-500 focus:bg-white focus:border-purple-300 focus:outline-none focus:shadow-outline-purple form-input"
|
|
type="text"
|
|
placeholder="Search products, orders..."
|
|
aria-label="Search" />
|
|
</div>
|
|
</div>
|
|
|
|
<ul class="flex items-center flex-shrink-0 space-x-6">
|
|
<!-- Theme toggler -->
|
|
<li class="flex">
|
|
<button class="rounded-md focus:outline-none focus:shadow-outline-purple"
|
|
@click="toggleTheme"
|
|
aria-label="Toggle color mode">
|
|
<template x-if="!dark">
|
|
<span x-html="$icon('moon', 'w-5 h-5')"></span>
|
|
</template>
|
|
<template x-if="dark">
|
|
<span x-html="$icon('sun', 'w-5 h-5')"></span>
|
|
</template>
|
|
</button>
|
|
</li>
|
|
|
|
<!-- Language selector -->
|
|
<li class="relative" x-data="{
|
|
isLangOpen: false,
|
|
currentLang: '{{ request.state.language|default("fr") }}',
|
|
languages: ['en', 'fr', 'de', 'lb'],
|
|
languageNames: { 'en': 'English', 'fr': 'Francais', 'de': 'Deutsch', 'lb': 'Letzebuerg' },
|
|
languageFlags: { 'en': 'gb', 'fr': 'fr', 'de': 'de', 'lb': 'lu' },
|
|
async setLanguage(lang) {
|
|
if (lang === this.currentLang) {
|
|
this.isLangOpen = false;
|
|
return;
|
|
}
|
|
try {
|
|
const response = await fetch('/api/v1/language/set', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ language: lang })
|
|
});
|
|
if (response.ok) {
|
|
this.currentLang = lang;
|
|
window.location.reload();
|
|
}
|
|
} catch (error) {
|
|
console.error('Failed to set language:', error);
|
|
}
|
|
this.isLangOpen = false;
|
|
}
|
|
}">
|
|
<button
|
|
@click="isLangOpen = !isLangOpen"
|
|
@click.outside="isLangOpen = false"
|
|
class="p-1 rounded-md focus:outline-none focus:shadow-outline-purple"
|
|
aria-label="Change language"
|
|
>
|
|
<span class="fi text-lg" :class="'fi-' + languageFlags[currentLang]"></span>
|
|
</button>
|
|
<div
|
|
x-show="isLangOpen"
|
|
x-cloak
|
|
x-transition:enter="transition ease-out duration-100"
|
|
x-transition:enter-start="transform opacity-0 scale-95"
|
|
x-transition:enter-end="transform opacity-100 scale-100"
|
|
x-transition:leave="transition ease-in duration-75"
|
|
x-transition:leave-start="transform opacity-100 scale-100"
|
|
x-transition:leave-end="transform opacity-0 scale-95"
|
|
class="absolute right-0 w-44 mt-2 bg-white dark:bg-gray-700 rounded-lg shadow-lg border border-gray-100 dark:border-gray-600 py-1 z-50"
|
|
>
|
|
<template x-for="lang in languages" :key="lang">
|
|
<button
|
|
@click="setLanguage(lang)"
|
|
type="button"
|
|
class="flex items-center gap-3 w-full px-4 py-2 text-sm font-medium transition-colors"
|
|
:class="currentLang === lang
|
|
? 'bg-purple-50 dark:bg-purple-900/20 text-purple-700 dark:text-purple-300'
|
|
: 'text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-600'"
|
|
>
|
|
<span class="fi" :class="'fi-' + languageFlags[lang]"></span>
|
|
<span x-text="languageNames[lang]"></span>
|
|
<span x-show="currentLang === lang" x-html="$icon('check', 'w-4 h-4 ml-auto')" class="text-purple-600 dark:text-purple-400"></span>
|
|
</button>
|
|
</template>
|
|
</div>
|
|
</li>
|
|
|
|
<!-- Notifications menu -->
|
|
<li class="relative">
|
|
<button class="relative align-middle rounded-md focus:outline-none focus:shadow-outline-purple"
|
|
@click="toggleNotificationsMenu"
|
|
@keydown.escape="closeNotificationsMenu"
|
|
aria-label="Notifications"
|
|
aria-haspopup="true">
|
|
<span x-html="$icon('bell', 'w-5 h-5')"></span>
|
|
<!-- Notification badge -->
|
|
<span aria-hidden="true"
|
|
class="absolute top-0 right-0 inline-block w-3 h-3 transform translate-x-1 -translate-y-1 bg-red-600 border-2 border-white rounded-full dark:border-gray-800"></span>
|
|
</button>
|
|
|
|
<template x-if="isNotificationsMenuOpen">
|
|
<ul x-transition:leave="transition ease-in duration-150"
|
|
x-transition:leave-start="opacity-100"
|
|
x-transition:leave-end="opacity-0"
|
|
@click.away="closeNotificationsMenu"
|
|
@keydown.escape="closeNotificationsMenu"
|
|
class="absolute right-0 w-56 p-2 mt-2 space-y-2 text-gray-600 bg-white border border-gray-100 rounded-md shadow-md dark:text-gray-300 dark:border-gray-700 dark:bg-gray-700">
|
|
<li class="flex">
|
|
<a class="inline-flex items-center justify-between w-full px-2 py-1 text-sm font-semibold transition-colors duration-150 rounded-md hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-gray-800 dark:hover:text-gray-200"
|
|
href="#">
|
|
<span>New order received</span>
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
</template>
|
|
</li>
|
|
|
|
<!-- Profile menu -->
|
|
<li class="relative" x-data="{ profileOpen: false }">
|
|
<button class="align-middle rounded-full focus:shadow-outline-purple focus:outline-none"
|
|
@click="profileOpen = !profileOpen"
|
|
@keydown.escape="profileOpen = false"
|
|
aria-label="Account"
|
|
aria-haspopup="true">
|
|
<div class="w-8 h-8 rounded-full bg-purple-600 flex items-center justify-center text-white font-semibold">
|
|
<span x-text="currentUser.username?.charAt(0).toUpperCase() || '?'"></span>
|
|
</div>
|
|
</button>
|
|
|
|
<!-- Use x-show instead of x-if for reliability -->
|
|
<ul x-show="profileOpen"
|
|
x-cloak
|
|
x-transition:leave="transition ease-in duration-150"
|
|
x-transition:leave-start="opacity-100"
|
|
x-transition:leave-end="opacity-0"
|
|
@click.away="profileOpen = false"
|
|
@keydown.escape="profileOpen = false"
|
|
class="absolute right-0 w-56 p-2 mt-2 space-y-2 text-gray-600 bg-white border border-gray-100 rounded-md shadow-md dark:border-gray-700 dark:text-gray-300 dark:bg-gray-700 z-50"
|
|
style="display: none;"
|
|
aria-label="submenu">
|
|
<li class="flex">
|
|
<a class="inline-flex items-center w-full px-2 py-1 text-sm font-semibold transition-colors duration-150 rounded-md hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-gray-800 dark:hover:text-gray-200"
|
|
:href="`/vendor/${vendorCode}/profile`">
|
|
<span x-html="$icon('user', 'w-4 h-4 mr-3')"></span>
|
|
<span>Profile</span>
|
|
</a>
|
|
</li>
|
|
<li class="flex">
|
|
<a class="inline-flex items-center w-full px-2 py-1 text-sm font-semibold transition-colors duration-150 rounded-md hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-gray-800 dark:hover:text-gray-200"
|
|
:href="`/vendor/${vendorCode}/settings`">
|
|
<span x-html="$icon('cog', 'w-4 h-4 mr-3')"></span>
|
|
<span>Settings</span>
|
|
</a>
|
|
</li>
|
|
<li class="flex">
|
|
<button
|
|
@click="handleLogout()"
|
|
class="inline-flex items-center w-full px-2 py-1 text-sm font-semibold transition-colors duration-150 rounded-md hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-gray-800 dark:hover:text-gray-200 text-left">
|
|
<span x-html="$icon('logout', 'w-4 h-4 mr-3')"></span>
|
|
<span>Log out</span>
|
|
</button>
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</header> |