0.0.26 • Published 8 months ago

@ecoding/helper.i18n v0.0.26

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

@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
0.0.20

9 months ago

0.0.21

9 months ago

0.0.22

9 months ago

0.0.23

9 months ago

0.0.24

8 months ago

0.0.25

8 months ago

0.0.15

10 months ago

0.0.16

10 months ago

0.0.17

10 months ago

0.0.18

9 months ago

0.0.19

9 months ago

0.0.10

10 months ago

0.0.11

10 months ago

0.0.12

10 months ago

0.0.13

10 months ago

0.0.14

10 months ago

0.0.26

8 months ago

0.0.9

10 months ago

0.0.8

11 months ago

0.0.7

11 months ago

0.0.6

11 months ago

0.0.5

11 months ago

0.0.4

11 months ago

0.0.3

11 months ago

0.0.2

11 months ago