You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

36 lines
852 B

"use client";
import { createContext, type ReactNode, useContext, useMemo } from "react";
import { defaultLocale, type Locale } from "@/translations/config";
import { type Dictionary, getDictionary } from "@/translations/dictionaries";
type I18nContextValue = {
locale: Locale;
dictionary: Dictionary;
};
const I18nContext = createContext<I18nContextValue>({
locale: defaultLocale,
dictionary: getDictionary(defaultLocale),
});
type I18nProviderProps = {
children: ReactNode;
locale: Locale;
};
export function I18nProvider({ children, locale }: I18nProviderProps) {
const value = useMemo(
() => ({
locale,
dictionary: getDictionary(locale),
}),
[locale],
);
return <I18nContext.Provider value={value}>{children}</I18nContext.Provider>;
}
export function useI18n() {
return useContext(I18nContext);
}