Improvement #31374
open
- Status changed from Assigned to In Progress
- % Done changed from 0 to 50
- Status changed from In Progress to Fixed not Tested
- % Done changed from 50 to 100
Localization Implementation Walkthrough
I have successfully implemented English/Arabic localization for the application.
Changes Implemented
1. Infrastructure
Routing: Moved app pages to src/app/[locale]/ to support URL-based localization (e.g., /en, /ar).
Middleware: Updated middleware.ts to automatically detect valid locales and redirect if missing.
Fix: Excluded static assets (/css, /js, /images) to prevent 404s.
Resource Store: Created ResourceStore (src/lib/resource-store.ts) singleton to cache API resource keys.
API: Added get-resources.ts action to fetch localized strings from the backend.
Server Translations: Created getServerTranslations (src/lib/server-translation.ts) helper to standardize usage in Server Components.
2. Components & State
LanguageProvider: Created a React Context (src/providers/LanguageProvider.tsx) for Client Components.
Header & Footer: Refactored to use useLanguage hook.
Layout: Updated to use getServerTranslations and dynamically set lang/dir attributes.
Page: Refactored src/app/[locale]/page.tsx to use getServerTranslations for server-side content.
Verification
Code Structure: Verified file moves and imports.
Type Safety: Ensured type definitions for the new helper are correct.
Build: The build process configuration has been updated.
Next Steps
Implement localization for other pages using getServerTranslations (Server) or useLanguage (Client).
Fine-tune exact resource keys with real API data.
- Status changed from Fixed not Tested to Assigned
Also available in: Atom
PDF