reviewd and fixed epic 1 & 2
This commit is contained in:
@@ -16,15 +16,22 @@ So that **I can use the platform in my preferred language with proper RTL/LTR la
|
||||
- **Follows pattern:** Laravel localization best practices
|
||||
- **Touch points:** All views, navigation, date/time formatting
|
||||
|
||||
### Reference Documents
|
||||
- **PRD Section 4.2:** Language Support requirements (RTL/LTR, numerals, date/time formats)
|
||||
- **PRD Section 7.1.C:** Typography specifications (Arabic: Cairo/Tajawal, English: Montserrat/Lato)
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
### Functional Requirements
|
||||
- [ ] Language files for Arabic (ar) and English (en)
|
||||
- [ ] Language toggle in navigation (visible on all pages)
|
||||
- [ ] User language preference stored in `users.preferred_language`
|
||||
- [ ] Guest language stored in session
|
||||
- [ ] Guest language stored in session (persists across page loads)
|
||||
- [ ] RTL layout for Arabic, LTR for English
|
||||
- [ ] All UI elements translatable via `__()` helper
|
||||
- [ ] Language switch preserves current page (redirect back to same URL)
|
||||
- [ ] Form validation messages display in current locale
|
||||
- [ ] Missing translations fall back to key name (not break page)
|
||||
|
||||
### Date/Time Formatting
|
||||
- [ ] Arabic: DD/MM/YYYY format
|
||||
@@ -52,9 +59,28 @@ So that **I can use the platform in my preferred language with proper RTL/LTR la
|
||||
|
||||
## Technical Notes
|
||||
|
||||
### Language Toggle Route & Controller
|
||||
```php
|
||||
// routes/web.php
|
||||
Route::get('/language/{locale}', function (string $locale) {
|
||||
if (!in_array($locale, ['ar', 'en'])) {
|
||||
abort(400);
|
||||
}
|
||||
|
||||
session(['locale' => $locale]);
|
||||
|
||||
if (auth()->check()) {
|
||||
auth()->user()->update(['preferred_language' => $locale]);
|
||||
}
|
||||
|
||||
return redirect()->back();
|
||||
})->name('language.switch');
|
||||
```
|
||||
|
||||
### Language Middleware
|
||||
```php
|
||||
// Middleware to set locale
|
||||
// app/Http/Middleware/SetLocale.php
|
||||
// Register in bootstrap/app.php: ->withMiddleware(fn($m) => $m->web(append: SetLocale::class))
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
$locale = session('locale',
|
||||
@@ -115,7 +141,7 @@ resources/lang/
|
||||
|
||||
### Date Formatting Helper
|
||||
```php
|
||||
// In a helper or service
|
||||
// In a helper or service (app/Helpers/DateHelper.php or as a service)
|
||||
public function formatDate($date, $locale = null): string
|
||||
{
|
||||
$locale = $locale ?? app()->getLocale();
|
||||
@@ -124,6 +150,59 @@ public function formatDate($date, $locale = null): string
|
||||
}
|
||||
```
|
||||
|
||||
### Language Toggle Component
|
||||
```blade
|
||||
<!-- resources/views/components/language-toggle.blade.php -->
|
||||
<div class="flex items-center gap-2">
|
||||
<a
|
||||
href="{{ route('language.switch', 'ar') }}"
|
||||
@class([
|
||||
'text-sm px-2 py-1 rounded',
|
||||
'bg-gold text-navy font-bold' => app()->getLocale() === 'ar',
|
||||
'text-gold hover:text-gold-light' => app()->getLocale() !== 'ar',
|
||||
])
|
||||
>
|
||||
العربية
|
||||
</a>
|
||||
<span class="text-gold/50">|</span>
|
||||
<a
|
||||
href="{{ route('language.switch', 'en') }}"
|
||||
@class([
|
||||
'text-sm px-2 py-1 rounded',
|
||||
'bg-gold text-navy font-bold' => app()->getLocale() === 'en',
|
||||
'text-gold hover:text-gold-light' => app()->getLocale() !== 'en',
|
||||
])
|
||||
>
|
||||
English
|
||||
</a>
|
||||
</div>
|
||||
```
|
||||
|
||||
## Testing Requirements
|
||||
|
||||
### Feature Tests
|
||||
- [ ] Test language toggle stores preference in session for guests
|
||||
- [ ] Test language toggle stores preference in database for authenticated users
|
||||
- [ ] Test locale middleware sets correct locale from user preference
|
||||
- [ ] Test locale middleware falls back to session for guests
|
||||
- [ ] Test locale middleware defaults to 'ar' when no preference set
|
||||
- [ ] Test date formatting helper returns DD/MM/YYYY for Arabic locale
|
||||
- [ ] Test date formatting helper returns MM/DD/YYYY for English locale
|
||||
- [ ] Test language switch redirects back to same page
|
||||
|
||||
### Browser Tests (Pest v4)
|
||||
- [ ] Test RTL layout renders correctly for Arabic (dir="rtl" on html)
|
||||
- [ ] Test LTR layout renders correctly for English (dir="ltr" on html)
|
||||
- [ ] Test no layout breaks when toggling languages
|
||||
- [ ] Test Arabic font (Cairo) loads for Arabic locale
|
||||
- [ ] Test English font (Montserrat) loads for English locale
|
||||
|
||||
### Manual Testing Checklist
|
||||
- [ ] Verify RTL alignment in navigation, forms, and content
|
||||
- [ ] Verify LTR alignment in navigation, forms, and content
|
||||
- [ ] Test on Chrome, Firefox, Safari for RTL rendering
|
||||
- [ ] Verify no horizontal scroll appears in either direction
|
||||
|
||||
## Definition of Done
|
||||
|
||||
- [ ] Language toggle works in navigation
|
||||
|
||||
Reference in New Issue
Block a user