From c489febfdd7abbbb8d5dfee6e2ff73eb599c28bb Mon Sep 17 00:00:00 2001 From: drafish Date: Mon, 8 Jul 2024 10:38:27 +0800 Subject: [PATCH] i18n for quick-dapp --- apps/quick-dapp/src/App.tsx | 39 +++++++++---- .../src/components/ContractGUI/index.tsx | 6 +- .../src/components/CreateInstance/index.tsx | 24 ++++---- .../src/components/DeployPanel/index.tsx | 55 ++++++++++--------- .../src/components/DeployPanel/theme.tsx | 3 +- .../src/components/EditInstance/index.tsx | 6 +- .../src/components/ImageUpload/index.tsx | 6 +- .../components/MultipleContainers/index.tsx | 6 +- .../src/app/tabs/locales/en/quickDapp.json | 40 ++++++++++++++ 9 files changed, 127 insertions(+), 58 deletions(-) create mode 100644 apps/remix-ide/src/app/tabs/locales/en/quickDapp.json diff --git a/apps/quick-dapp/src/App.tsx b/apps/quick-dapp/src/App.tsx index 5adacb2e2f..c01f92bb7d 100644 --- a/apps/quick-dapp/src/App.tsx +++ b/apps/quick-dapp/src/App.tsx @@ -1,4 +1,5 @@ -import React, { useEffect, useReducer } from 'react'; +import React, { useEffect, useReducer, useState } from 'react'; +import { IntlProvider } from 'react-intl' import CreateInstance from './components/CreateInstance'; import EditInstance from './components/EditInstance'; import DeployPanel from './components/DeployPanel'; @@ -15,6 +16,10 @@ import remixClient from './remix-client'; import './App.css'; function App(): JSX.Element { + const [locale, setLocale] = useState<{code: string; messages: any}>({ + code: 'en', + messages: null, + }) const [appState, dispatch] = useReducer(appReducer, appInitialState); useEffect(() => { updateState(appState); @@ -29,6 +34,14 @@ function App(): JSX.Element { remixClient.on('theme', 'themeChanged', (theme: any) => { selectTheme(theme.name); }); + // @ts-ignore + remixClient.call('locale', 'currentLocale').then((locale: any) => { + setLocale(locale) + }) + // @ts-ignore + remixClient.on('locale', 'localeChanged', (locale: any) => { + setLocale(locale) + }) }); }, []); return ( @@ -38,17 +51,19 @@ function App(): JSX.Element { appState, }} > - {Object.keys(appState.instance.abi).length > 0 ? ( -
- - -
- ) : ( -
- -
- )} - + + {Object.keys(appState.instance.abi).length > 0 ? ( +
+ + +
+ ) : ( +
+ +
+ )} + +
); } diff --git a/apps/quick-dapp/src/components/ContractGUI/index.tsx b/apps/quick-dapp/src/components/ContractGUI/index.tsx index 0976531c9e..50f4f6a424 100644 --- a/apps/quick-dapp/src/components/ContractGUI/index.tsx +++ b/apps/quick-dapp/src/components/ContractGUI/index.tsx @@ -1,4 +1,5 @@ import React, { useEffect, useState } from 'react'; +import { useIntl } from 'react-intl'; import { execution } from '@remix-project/remix-lib'; import { saveDetails, saveTitle } from '../../actions'; @@ -12,6 +13,7 @@ const getFuncABIInputs = (funABI: any) => { }; export function ContractGUI(props: { funcABI: any }) { + const intl = useIntl() const isConstant = props.funcABI.constant !== undefined ? props.funcABI.constant : false; const lookupOnly = @@ -68,7 +70,7 @@ export function ContractGUI(props: { funcABI: any }) {
{ saveTitle({ id: props.funcABI.id, title: value }); @@ -116,7 +118,7 @@ export function ContractGUI(props: { funcABI: any }) {