Add localization support and docs
This commit is contained in:
24
src/hooks/useLanguage.js
Normal file
24
src/hooks/useLanguage.js
Normal file
@@ -0,0 +1,24 @@
|
||||
import React from 'react';
|
||||
import { translations, getInitialLanguage } from '../locales/index.js';
|
||||
|
||||
export const useLanguage = () => {
|
||||
const [currentLanguage, setCurrentLanguage] = React.useState(getInitialLanguage);
|
||||
|
||||
// Get current translations
|
||||
const t = translations[currentLanguage] || translations.en;
|
||||
|
||||
// Change language and save to localStorage
|
||||
const changeLanguage = (lang) => {
|
||||
if (translations[lang]) {
|
||||
setCurrentLanguage(lang);
|
||||
localStorage.setItem('medPlanAssistant_language', lang);
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
currentLanguage,
|
||||
changeLanguage,
|
||||
t,
|
||||
availableLanguages: Object.keys(translations)
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user