You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implemented internationalization (i18n) support for French and English languages
Added language switcher components with multiple UI variants (standard, compact, minimal)
Created translation hook and context for managing locale state
Integrated translations across main pages and navigation components
Diagram Walkthrough
flowchart LR
A["Translation Files"] --> B["LanguageContext"]
B --> C["useTranslations Hook"]
C --> D["UI Components"]
E["LanguageSwitcher"] --> B
D --> F["Translated Pages"]
Below is a summary of compliance checks for this PR:
Security Compliance
⚪
Client storage trust
Description: Language preference is stored and read from localStorage without validation or namespace, which could be manipulated by third-party scripts; consider namespacing and validating the value against an allowed list. LanguageContext.tsx [21-31]
Referred Code
useEffect(()=>{// Récupérer la langue depuis localStorage au chargementconstsavedLocale=localStorage.getItem('preferred-language')||'en';setLocaleState(savedLocale);setIsLoading(false);},[]);constsetLocale=(newLocale: string)=>{setLocaleState(newLocale);localStorage.setItem('preferred-language',newLocale);};
Instead of the custom, client-side-only translation solution, use the next-i18next library that was already added as a dependency. This will provide proper Server-Side Rendering (SSR) support, improving performance and SEO.
exportfunctionLanguageProvider({ children }: LanguageProviderProps){const[locale,setLocaleState]=useState('en');const[isLoading,setIsLoading]=useState(true);useEffect(()=>{// Récupérer la langue depuis localStorage au chargementconstsavedLocale=localStorage.getItem('preferred-language')||'en';setLocaleState(savedLocale);setIsLoading(false);},[]);
... (clipped5lines)
Solution Walkthrough:
Before:
// LanguageContext.tsxfunctionLanguageProvider({ children }){const[locale,setLocaleState]=useState('en');useEffect(()=>{// Fetches language from client-side localStorageconstsavedLocale=localStorage.getItem('preferred-language')||'en';setLocaleState(savedLocale);},[]);// ...}// useTranslations.tsfunctionuseTranslations(){const{ locale }=useLanguage();useEffect(()=>{// Fetches translation files on the clientfetch(`/locales/${locale}/common.json`).then(res=>res.json()).then(data=>setTranslations(data));},[locale]);constt=(key,fallback)=>{/* ... */};return{ t };}
After:
// next-i18next.config.js (conceptual)module.exports={i18n: {defaultLocale: 'en',locales: ['en','fr'],},};// app/[locale]/page.tsx (App Router example)import{useTranslation}from'next-i18next';// Translations are loaded on the server via middleware/configexportdefaultfunctionPage(){// Hook provided by the libraryconst{ t }=useTranslation('common');// Renders translated content on the server, no fallback neededreturn<h1>{t('hero.title')}</h1>;}
Suggestion importance[1-10]: 9
__
Why: The suggestion correctly identifies a major architectural flaw where a custom, client-side-only i18n solution is built despite next-i18next being added as a dependency, which negatively impacts SSR, performance, and SEO.
High
Possible issue
Reset loading state on locale change
Add setIsLoading(true) at the beginning of the useEffect in the useTranslations hook to prevent displaying stale translations while a new language file is being fetched.
useEffect(() => {
const loadTranslations = async () => {
+ setIsLoading(true);
try {
const response = await fetch(`/locales/${locale}/common.json`);
if (!response.ok) {
throw new Error(`Failed to load translations for ${locale}`);
}
const data = await response.json();
setTranslations(data);
} catch (error) {
console.error('Failed to load translations:', error);
// Fallback to English
try {
const response = await fetch('/locales/en/common.json');
const data = await response.json();
setTranslations(data);
} catch (fallbackError) {
console.error('Failed to load fallback translations:', fallbackError);
setTranslations({});
}
} finally {
setIsLoading(false);
}
};
if (!contextLoading) {
loadTranslations();
}
}, [locale, contextLoading]);
Apply / Chat
Suggestion importance[1-10]: 8
__
Why: The suggestion correctly identifies a race condition where stale translations could be displayed when the language changes, which is a significant bug in the new i18n feature.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
PR Type
Enhancement, Documentation
Description
Implemented internationalization (i18n) support for French and English languages
Added language switcher components with multiple UI variants (standard, compact, minimal)
Created translation hook and context for managing locale state
Integrated translations across main pages and navigation components
Diagram Walkthrough
File Walkthrough
9 files
Create custom hook for translation managementAdd language context provider with localStorage persistenceCreate standard language switcher dropdown componentCreate compact language switcher with globe iconCreate minimal flag-only language switcher variantIntegrate translations and language switcher in navbarReplace hardcoded text with translation keysWrap app with LanguageProvider and update metadataAdd translation support for button text2 files
Add English translation strings for all UI elementsAdd French translation strings for all UI elements1 files
Add i18n dependencies (i18next, react-i18next, next-i18next)4 files
Adjust navbar spacing and alignment for language switcherRemove unused Image importRemove trailing newlineRemove trailing newline1 files
Update imports and add navbar component