Advertisement
Guest User

Untitled

a guest
Dec 15th, 2024
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import i18next from 'i18next'
  2. import create from 'zustand'
  3.  
  4. // Define the store type
  5. interface LanguageState {
  6.   language: string
  7.   setLanguage: (newLanguage: string) => void
  8. }
  9.  
  10. // Create the store
  11. const useLanguageStore = create<LanguageState>((set) => ({
  12.   language: 'EN',
  13.   setLanguage: (newLanguage) => set({ language: newLanguage })
  14. }))
  15.  
  16. // Subscribe to language changes and update i18next
  17. useLanguageStore.subscribe(
  18.   (state) => state.language,
  19.   (language) => {
  20.     i18next.changeLanguage(language)
  21.   }
  22. )
  23.  
  24. export default useLanguageStore
  25.  
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement