Added the foundation for making the frontend multilingual. Now only need to import useTranslation and use t('key') for all user-facing text for all pages (+add key:value pairs in src/locales for each language ofc)
- package.json -> Imported packages i18next & react-i18next for multilingual functionality. - src/App.jsx -> Imported LanguageSwitcher from ./components/LanguageSwitcher and added <LanguageSwitcher /> component at the beginning of layout so it's always visible. - src/components/LanguageSwitcher.jsx -> LanguageSwitcher component, consists of a dropdown menu that always appears at top right corner for choosing language. - src/i18n.js -> Initialize and configure i18next for app-wide multilingual support. - src/locales/en.json + src/locales/fr.json -> Empty json files that will soon contain translation key:value pairs for each page. - src/main.jsx -> Imported src/i18n.js for multilingual functionality.
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import React from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
const languages = [
|
||||
{ code: 'en', label: 'English' },
|
||||
{ code: 'fr', label: 'Français' },
|
||||
// Add more languages as needed
|
||||
];
|
||||
|
||||
function LanguageSwitcher() {
|
||||
const { i18n } = useTranslation();
|
||||
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
position: 'absolute',
|
||||
top: '1rem',
|
||||
right: '1rem',
|
||||
zIndex: 1000,
|
||||
background: 'rgba(255,255,255,0.95)',
|
||||
borderRadius: '4px',
|
||||
padding: '0.25em 0.5em',
|
||||
boxShadow: '0 2px 8px rgba(0,0,0,0.05)'
|
||||
}}
|
||||
>
|
||||
<select
|
||||
value={i18n.language}
|
||||
onChange={e => i18n.changeLanguage(e.target.value)}
|
||||
style={{
|
||||
border: '1px solid #ccc',
|
||||
borderRadius: '4px',
|
||||
padding: '0.25em 2em 0.25em 0.5em', // More right padding for arrow
|
||||
minWidth: '100px',
|
||||
appearance: 'auto', // Use browser default arrow
|
||||
background: '#fff',
|
||||
}}
|
||||
|
||||
aria-label="Select language"
|
||||
>
|
||||
{languages.map(lang => (
|
||||
<option key={lang.code} value={lang.code}>
|
||||
{lang.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default LanguageSwitcher;
|
||||
|
||||
Reference in New Issue
Block a user