mirror of
https://github.com/wgh136/nysoure.git
synced 2025-09-27 04:17:23 +00:00
22 lines
460 B
TypeScript
22 lines
460 B
TypeScript
import { createContext, useContext, useMemo } from "react";
|
|
|
|
function t(data: any, language: string) {
|
|
return (key: string) => {
|
|
return data[language]?.["translation"]?.[key] || key;
|
|
};
|
|
}
|
|
|
|
export const i18nContext = createContext<any>({});
|
|
|
|
export function useTranslation() {
|
|
const data = useContext(i18nContext);
|
|
const userLang = navigator.language;
|
|
|
|
return useMemo(
|
|
() => ({
|
|
t: t(data, userLang),
|
|
}),
|
|
[data, userLang],
|
|
);
|
|
}
|