Perf: i18n ns (#1441)

* i18n

* fix: handle
This commit is contained in:
Archer
2024-05-10 18:41:41 +08:00
committed by GitHub
parent f351d4ea68
commit 26f4c92124
27 changed files with 1705 additions and 1595 deletions

View File

@@ -0,0 +1,38 @@
import { createContext, useContextSelector } from 'use-context-selector';
import { useTranslation } from 'next-i18next';
import { TFunction } from 'i18next';
type I18nContextType = {
commonT: TFunction<['common'], undefined>;
appT: TFunction<['app'], undefined>;
datasetT: TFunction<['dataset'], undefined>;
};
export const I18nContext = createContext<I18nContextType>({
// @ts-ignore
commonT: undefined
});
const I18nContextProvider = ({ children }: { children: React.ReactNode }) => {
const { t: commonT } = useTranslation('common');
const { t: appT } = useTranslation('app');
const { t: datasetT } = useTranslation('dataset');
return (
<I18nContext.Provider
value={{
commonT,
appT,
datasetT
}}
>
{children}
</I18nContext.Provider>
);
};
export default I18nContextProvider;
export const useI18n = () => {
return useContextSelector(I18nContext, (ctx) => ctx);
};