UNPKG

ze-react-component-library

Version:
30 lines (27 loc) 815 B
import "antd/es/config-provider/style"; import _ConfigProvider from "antd/es/config-provider"; import { useContext, useEffect } from "react"; import i18n from "i18next"; import { useTranslation, initReactI18next } from "react-i18next"; import locales from "../locales"; i18n.use(initReactI18next).init({ resources: locales, fallbackLng: "zh-CN", interpolation: { escapeValue: false } }); export default function useLocale() { var _a; var locale = (_a = useContext(_ConfigProvider.ConfigContext)) === null || _a === void 0 ? void 0 : _a.locale; var lng = (locale === null || locale === void 0 ? void 0 : locale.locale) || "zh-CN"; var _b = useTranslation(), t = _b.t, rI18n = _b.i18n; useEffect(function () { rI18n.changeLanguage(lng); }, [lng]); return { t: t }; }