@ecoding/helper.i18n
v0.0.26
Published
dev qs
Downloads
28
Readme
@ecoding/helper.i18n
TODO: description
Usage
import { i18nInstance } from "@ecoding/helper.i18n";
import { getCookie } from "@ecoding/helper.cookie";
import localStorage from "@ecoding/helper.storage.local";
// project locale
import zh_CN from "./zh_CN";
import en_US from "./en_US";
const getLocales = (locale) => {
const map = {
zh: zh_CN,
en: en_US
};
if (locale === "all") {
return map;
}
return map[locale];
};
const i18n = i18nInstance.config({
locales: getLocales("all"),
def: "en"
});
const localLocale = getCookie('locale') || localStorage.getStore('locale')
if (localLocale) {
i18n.switch(localLocale);
}
export default i18n;
// intl 版本
import React from "react";
import { Provider } from "react-redux";
import { IntlProvider } from "react-intl";
import { ConfigProvider } from "antd";
import { InjectNotification } from "@ecoding/components.antd";
import Routes from "./routes";
import Layout from "./layouts";
import { theme } from "@/theme";
import getLocale from "@/locales";
import type { TStore } from "./redux.configure.store";
const App: React.FC<{ store: TStore }> = ({ store }) => {
const state = store.getState();
const locale = getLocale(state.global.locale, state.global.language);
return (
<Provider store={store}>
<IntlProvider locale={state.global.locale || "zh"} messages={locale}>
<ConfigProvider locale={locale} theme={theme}>
<Layout>
<Routes />
</Layout>
<InjectNotification />
</ConfigProvider>
</IntlProvider>
</Provider>
);
};
export default App;
import { useIntl, FormattedMessage } from "react-intl";
React.FC(){
const intl = useIntl();
return {intl.formatMessage({ id: "form.platformId" })}
return <FormattedMessage id="head.userName" values={{ name: user?.userName }} />
}
// TODO: DEMONSTRATE API