feat: 多语言
This commit is contained in:
parent
016f948610
commit
98a9c6a0a3
|
|
@ -0,0 +1,9 @@
|
||||||
|
import React from "react";
|
||||||
|
import { ConfigProviderProps } from "./types";
|
||||||
|
import { ConfigContext } from "./context";
|
||||||
|
|
||||||
|
const ConfigProvider: React.FC<ConfigProviderProps> = ({ children, t = (v) => v }) => {
|
||||||
|
return <ConfigContext.Provider value={{ t }}>{children}</ConfigContext.Provider>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ConfigProvider;
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
import React from "react";
|
||||||
|
import { ConfigProviderProps } from "./types";
|
||||||
|
|
||||||
|
export const ConfigContext = React.createContext<ConfigProviderProps>({
|
||||||
|
t: (val) => val,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default ConfigContext;
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
export { default as ConfigProvider } from "./ConfigProvider";
|
||||||
|
export type { ConfigProviderProps } from "./types";
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
import { ReactText } from "react";
|
||||||
|
|
||||||
|
type ContextData = {
|
||||||
|
[key: string]: ReactText;
|
||||||
|
};
|
||||||
|
|
||||||
|
export interface ConfigProviderProps {
|
||||||
|
t: (key: string, data?: ContextData) => string;
|
||||||
|
}
|
||||||
|
|
@ -30,6 +30,7 @@ export * from "./components/TabMenu";
|
||||||
export * from "./components/Tag";
|
export * from "./components/Tag";
|
||||||
export * from "./components/Text";
|
export * from "./components/Text";
|
||||||
export * from "./components/Toggle";
|
export * from "./components/Toggle";
|
||||||
|
export * from "./components/ConfigProvider";
|
||||||
|
|
||||||
// Hooks
|
// Hooks
|
||||||
export * from "./hooks";
|
export * from "./hooks";
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
import React from "react";
|
import React, { useContext } from "react";
|
||||||
import Button from "../../../components/Button/Button";
|
import Button from "../../../components/Button/Button";
|
||||||
import { useModal } from "../../Modal";
|
import { useModal } from "../../Modal";
|
||||||
import InviteModal from "./InviteModal";
|
import InviteModal from "./InviteModal";
|
||||||
import { useWalletModal } from "../../WalletModal";
|
import { useWalletModal } from "../../WalletModal";
|
||||||
import { Login } from "../../WalletModal/types";
|
import { Login } from "../../WalletModal/types";
|
||||||
|
import { ConfigContext } from "../../../components/ConfigProvider/context";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
account?: string;
|
account?: string;
|
||||||
|
|
@ -13,6 +14,7 @@ interface Props {
|
||||||
}
|
}
|
||||||
|
|
||||||
const UserBlock: React.FC<Props> = ({ account, login, logout, inviteUrl }) => {
|
const UserBlock: React.FC<Props> = ({ account, login, logout, inviteUrl }) => {
|
||||||
|
const { t } = useContext(ConfigContext);
|
||||||
const { onPresentConnectModal, onPresentAccountModal } = useWalletModal(login, logout, account);
|
const { onPresentConnectModal, onPresentAccountModal } = useWalletModal(login, logout, account);
|
||||||
const [onPresentInviteModal] = useModal(<InviteModal inviteUrl={inviteUrl} />);
|
const [onPresentInviteModal] = useModal(<InviteModal inviteUrl={inviteUrl} />);
|
||||||
const accountEllipsis = account ? `${account.substring(0, 4)}...${account.substring(account.length - 4)}` : null;
|
const accountEllipsis = account ? `${account.substring(0, 4)}...${account.substring(account.length - 4)}` : null;
|
||||||
|
|
@ -25,7 +27,7 @@ const UserBlock: React.FC<Props> = ({ account, login, logout, inviteUrl }) => {
|
||||||
onPresentInviteModal();
|
onPresentInviteModal();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Invite
|
{t("Invite")}
|
||||||
</Button>
|
</Button>
|
||||||
{account ? (
|
{account ? (
|
||||||
<Button
|
<Button
|
||||||
|
|
@ -44,7 +46,7 @@ const UserBlock: React.FC<Props> = ({ account, login, logout, inviteUrl }) => {
|
||||||
onPresentConnectModal();
|
onPresentConnectModal();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Connect
|
{t("Connect")}
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue