Skip to content

Commit 0e86750

Browse files
Localization replacement (pancakeswap#234)
* chore: Update CardNav * chore: Update SlippageToleranceSettings Localization * refactor: Memoize translation function * chore: Replace TranslatedText * chore: Add Translation IDs * fix(i18n): Updated CurrencyInputPanel translation * fix: Type error * chore: Remove TranslatedText Co-authored-by: hachiojidev <[email protected]>
1 parent 70b9eb2 commit 0e86750

File tree

15 files changed

+173
-154
lines changed

15 files changed

+173
-154
lines changed

src/components/AddressInputPanel/index.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useCallback } from 'react'
22
import styled from 'styled-components'
33
import { Text } from '@pancakeswap-libs/uikit'
4+
import useI18n from 'hooks/useI18n'
45
import useENS from '../../hooks/useENS'
56
import { useActiveWeb3React } from '../../hooks'
67
import { ExternalLink } from '../Shared'
@@ -79,7 +80,7 @@ export default function AddressInputPanel({
7980
onChange: (value: string) => void
8081
}) {
8182
const { chainId } = useActiveWeb3React()
82-
83+
const TranslateString = useI18n()
8384
const { address, loading, name } = useENS(value)
8485

8586
const handleInput = useCallback(
@@ -100,11 +101,11 @@ export default function AddressInputPanel({
100101
<AutoColumn gap="md">
101102
<RowBetween>
102103
<Text color="textSubtle" fontWeight={500} fontSize="14px">
103-
Recipient
104+
{TranslateString(1138, 'Recipient')}
104105
</Text>
105106
{address && chainId && (
106107
<ExternalLink href={getBscScanLink(chainId, name ?? address, 'address')} style={{ fontSize: '14px' }}>
107-
(View on BscScan)
108+
{TranslateString(116, '(View on BscScan)')}
108109
</ExternalLink>
109110
)}
110111
</RowBetween>
@@ -115,7 +116,7 @@ export default function AddressInputPanel({
115116
autoCorrect="off"
116117
autoCapitalize="off"
117118
spellCheck="false"
118-
placeholder="Wallet Address or ENS name"
119+
placeholder={TranslateString(1140, 'Wallet Address or ENS name')}
119120
error={error}
120121
pattern="^(0x[a-fA-F0-9]{40})$"
121122
onChange={handleInput}

src/components/CardNav/index.tsx

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,35 @@ import React from 'react'
22
import styled from 'styled-components'
33
import { Link } from 'react-router-dom'
44
import { ButtonMenu, ButtonMenuItem } from '@pancakeswap-libs/uikit'
5-
import TranslatedText from '../TranslatedText'
5+
import useI18n from 'hooks/useI18n'
66

77
const StyledNav = styled.div`
88
margin-bottom: 40px;
99
`
1010

11-
const Nav = ({ activeIndex = 0 }: { activeIndex?: number }) => (
12-
<StyledNav>
13-
<ButtonMenu activeIndex={activeIndex} scale="sm" variant="subtle">
14-
<ButtonMenuItem id="swap-nav-link" to="/swap" as={Link}>
15-
<TranslatedText translationId={8}>Swap</TranslatedText>
16-
</ButtonMenuItem>
17-
<ButtonMenuItem id="pool-nav-link" to="/pool" as={Link}>
18-
<TranslatedText translationId={74}>Liquidity</TranslatedText>
19-
</ButtonMenuItem>
20-
<ButtonMenuItem
21-
id="pool-nav-link"
22-
as="a"
23-
href="https://www.binance.org/en/bridge?utm_source=PancakeSwap"
24-
target="_blank"
25-
rel="noreferrer noopener"
26-
>
27-
Bridge
28-
</ButtonMenuItem>
29-
</ButtonMenu>
30-
</StyledNav>
31-
)
11+
function Nav({ activeIndex = 0 }: { activeIndex?: number }) {
12+
const TranslateString = useI18n()
13+
return (
14+
<StyledNav>
15+
<ButtonMenu activeIndex={activeIndex} scale="sm" variant="subtle">
16+
<ButtonMenuItem id="swap-nav-link" to="/swap" as={Link}>
17+
{TranslateString(1142, 'Swap')}
18+
</ButtonMenuItem>
19+
<ButtonMenuItem id="pool-nav-link" to="/pool" as={Link}>
20+
{TranslateString(262, 'Liquidity')}
21+
</ButtonMenuItem>
22+
<ButtonMenuItem
23+
id="pool-nav-link"
24+
as="a"
25+
href="https://www.binance.org/en/bridge?utm_source=PancakeSwap"
26+
target="_blank"
27+
rel="noreferrer noopener"
28+
>
29+
Bridge
30+
</ButtonMenuItem>
31+
</ButtonMenu>
32+
</StyledNav>
33+
)
34+
}
3235

3336
export default Nav

src/components/CurrencyInputPanel/index.tsx

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,21 @@ import { Currency, Pair } from '@pancakeswap-libs/sdk'
33
import { Button, ChevronDownIcon, Text } from '@pancakeswap-libs/uikit'
44
import styled from 'styled-components'
55
import { darken } from 'polished'
6+
import useI18n from 'hooks/useI18n'
67
import { useCurrencyBalance } from '../../state/wallet/hooks'
78
import CurrencySearchModal from '../SearchModal/CurrencySearchModal'
89
import CurrencyLogo from '../CurrencyLogo'
910
import DoubleCurrencyLogo from '../DoubleLogo'
1011
import { RowBetween } from '../Row'
1112
import { Input as NumericalInput } from '../NumericalInput'
1213
import { useActiveWeb3React } from '../../hooks'
13-
import TranslatedText from '../TranslatedText'
14-
import { TranslateString } from '../../utils/translateTextHelpers'
1514

1615
const InputRow = styled.div<{ selected: boolean }>`
1716
display: flex;
1817
flex-flow: row nowrap;
1918
align-items: center;
2019
padding: ${({ selected }) => (selected ? '0.75rem 0.5rem 0.75rem 1rem' : '0.75rem 0.75rem 0.75rem 1rem')};
2120
`
22-
2321
const CurrencySelect = styled.button<{ selected: boolean }>`
2422
align-items: center;
2523
height: 34px;
@@ -33,13 +31,11 @@ const CurrencySelect = styled.button<{ selected: boolean }>`
3331
user-select: none;
3432
border: none;
3533
padding: 0 0.5rem;
36-
3734
:focus,
3835
:hover {
3936
background-color: ${({ theme }) => darken(0.05, theme.colors.input)};
4037
}
4138
`
42-
4339
const LabelRow = styled.div`
4440
display: flex;
4541
flex-flow: row nowrap;
@@ -53,13 +49,11 @@ const LabelRow = styled.div`
5349
color: ${({ theme }) => darken(0.2, theme.colors.textSubtle)};
5450
}
5551
`
56-
5752
const Aligner = styled.span`
5853
display: flex;
5954
align-items: center;
6055
justify-content: space-between;
6156
`
62-
6357
const InputPanel = styled.div<{ hideInput?: boolean }>`
6458
display: flex;
6559
flex-flow: column nowrap;
@@ -68,13 +62,11 @@ const InputPanel = styled.div<{ hideInput?: boolean }>`
6862
background-color: ${({ theme }) => theme.colors.background};
6963
z-index: 1;
7064
`
71-
7265
const Container = styled.div<{ hideInput: boolean }>`
7366
border-radius: 16px;
7467
background-color: ${({ theme }) => theme.colors.input};
7568
box-shadow: ${({ theme }) => theme.shadows.inset};
7669
`
77-
7870
interface CurrencyInputPanelProps {
7971
value: string
8072
onUserInput: (value: string) => void
@@ -91,13 +83,12 @@ interface CurrencyInputPanelProps {
9183
id: string
9284
showCommonBases?: boolean
9385
}
94-
9586
export default function CurrencyInputPanel({
9687
value,
9788
onUserInput,
9889
onMax,
9990
showMaxButton,
100-
label = TranslateString(132, 'Input'),
91+
label,
10192
onCurrencySelect,
10293
currency,
10394
disableCurrencySelect = false,
@@ -111,18 +102,18 @@ export default function CurrencyInputPanel({
111102
const [modalOpen, setModalOpen] = useState(false)
112103
const { account } = useActiveWeb3React()
113104
const selectedCurrencyBalance = useCurrencyBalance(account ?? undefined, currency ?? undefined)
114-
105+
const TranslateString = useI18n()
106+
const translatedLabel = label || TranslateString(132, 'Input')
115107
const handleDismissSearch = useCallback(() => {
116108
setModalOpen(false)
117109
}, [setModalOpen])
118-
119110
return (
120111
<InputPanel id={id}>
121112
<Container hideInput={hideInput}>
122113
{!hideInput && (
123114
<LabelRow>
124115
<RowBetween>
125-
<Text fontSize="14px">{label}</Text>
116+
<Text fontSize="14px">{translatedLabel}</Text>
126117
{account && (
127118
<Text onClick={onMax} fontSize="14px" style={{ display: 'inline', cursor: 'pointer' }}>
128119
{!hideBalance && !!currency && selectedCurrencyBalance
@@ -176,7 +167,7 @@ export default function CurrencyInputPanel({
176167
currency.symbol.length - 5,
177168
currency.symbol.length
178169
)}`
179-
: currency?.symbol) || <TranslatedText translationId={82}>Select a currency</TranslatedText>}
170+
: currency?.symbol) || TranslateString(1196, 'Select a currency')}
180171
</Text>
181172
)}
182173
{!disableCurrencySelect && <ChevronDownIcon />}

src/components/PageHeader/SlippageToleranceSetting.tsx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import React, { useEffect, useState } from 'react'
22
import styled from 'styled-components'
33
import { Button, Flex, Input, Text } from '@pancakeswap-libs/uikit'
44
import { useUserSlippageTolerance } from 'state/user/hooks'
5+
import useI18n from 'hooks/useI18n'
56
import QuestionHelper from '../QuestionHelper'
6-
import TranslatedText from '../TranslatedText'
77

88
const MAX_SLIPPAGE = 5000
99
const RISKY_SLIPPAGE_LOW = 50
@@ -44,14 +44,13 @@ const Label = styled.div`
4444
const predefinedValues = [
4545
{ label: '0.1%', value: 0.1 },
4646
{ label: '0.5%', value: 0.5 },
47-
{ label: '1%', value: 1 }
47+
{ label: '1%', value: 1 },
4848
]
49-
5049
const SlippageToleranceSettings = () => {
50+
const TranslateString = useI18n()
5151
const [userSlippageTolerance, setUserslippageTolerance] = useUserSlippageTolerance()
5252
const [value, setValue] = useState(userSlippageTolerance / 100)
5353
const [error, setError] = useState<string | null>(null)
54-
5554
const handleChange = (evt: React.ChangeEvent<HTMLInputElement>) => {
5655
const { value: inputValue } = evt.target
5756
setValue(parseFloat(inputValue))
@@ -65,29 +64,32 @@ const SlippageToleranceSettings = () => {
6564
setUserslippageTolerance(rawValue)
6665
setError(null)
6766
} else {
68-
setError('Enter a valid slippage percentage')
67+
setError(TranslateString(1144, 'Enter a valid slippage percentage'))
6968
}
7069
} catch {
71-
setError('Enter a valid slippage percentage')
70+
setError(TranslateString(1144, 'Enter a valid slippage percentage'))
7271
}
73-
}, [value, setError, setUserslippageTolerance])
72+
}, [value, setError, setUserslippageTolerance, TranslateString])
7473

7574
// Notify user if slippage is risky
7675
useEffect(() => {
7776
if (userSlippageTolerance < RISKY_SLIPPAGE_LOW) {
78-
setError('Your transaction may fail')
77+
setError(TranslateString(1146, 'Your transaction may fail'))
7978
} else if (userSlippageTolerance > RISKY_SLIPPAGE_HIGH) {
80-
setError('Your transaction may be frontrun')
79+
setError(TranslateString(1148, 'Your transaction may be frontrun'))
8180
}
82-
}, [userSlippageTolerance, setError])
81+
}, [userSlippageTolerance, setError, TranslateString])
8382

8483
return (
8584
<StyledSlippageToleranceSettings>
8685
<Label>
87-
<Text style={{ fontWeight: 600 }}>
88-
<TranslatedText translationId={88}>Slippage tolerance</TranslatedText>
89-
</Text>
90-
<QuestionHelper text="Your transaction will revert if the price changes unfavorably by more than this percentage." />
86+
<Text style={{ fontWeight: 600 }}>{TranslateString(88, 'Slippage tolerance')}</Text>
87+
<QuestionHelper
88+
text={TranslateString(
89+
186,
90+
'Your transaction will revert if the price changes unfavorably by more than this percentage.'
91+
)}
92+
/>
9193
</Label>
9294
<Options>
9395
<Flex mb={['8px', 0]} mr={[0, '8px']}>

src/components/PageHeader/TransactionDeadlineSetting.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import React, { useEffect, useState } from 'react'
22
import styled from 'styled-components'
33
import { Input, Text } from '@pancakeswap-libs/uikit'
44
import { useUserDeadline } from 'state/user/hooks'
5+
import useI18n from 'hooks/useI18n'
56
import QuestionHelper from '../QuestionHelper'
6-
import TranslatedText from '../TranslatedText'
77

88
const StyledTransactionDeadlineSetting = styled.div`
99
margin-bottom: 16px;
@@ -30,6 +30,7 @@ const Field = styled.div`
3030
`
3131

3232
const TransactionDeadlineSetting = () => {
33+
const TranslateString = useI18n()
3334
const [deadline, setDeadline] = useUserDeadline()
3435
const [value, setValue] = useState(deadline / 60) // deadline in minutes
3536
const [error, setError] = useState<string | null>(null)
@@ -47,20 +48,20 @@ const TransactionDeadlineSetting = () => {
4748
setDeadline(rawValue)
4849
setError(null)
4950
} else {
50-
setError('Enter a valid deadline')
51+
setError(TranslateString(1150, 'Enter a valid deadline'))
5152
}
5253
} catch {
53-
setError('Enter a valid deadline')
54+
setError(TranslateString(1150, 'Enter a valid deadline'))
5455
}
55-
}, [value, setError, setDeadline])
56+
}, [value, setError, setDeadline, TranslateString])
5657

5758
return (
5859
<StyledTransactionDeadlineSetting>
5960
<Label>
60-
<Text style={{ fontWeight: 600 }}>
61-
<TranslatedText translationId={90}>Transaction deadline</TranslatedText>
62-
</Text>
63-
<QuestionHelper text="Your transaction will revert if it is pending for more than this long." />
61+
<Text style={{ fontWeight: 600 }}>{TranslateString(90, 'Transaction deadline')}</Text>
62+
<QuestionHelper
63+
text={TranslateString(188, 'Your transaction will revert if it is pending for more than this long.')}
64+
/>
6465
</Label>
6566
<Field>
6667
<Input type="number" step="1" min="1" value={value} onChange={handleChange} />

src/components/SearchModal/CurrencySearch.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useTranslation } from 'react-i18next'
66
import { FixedSizeList } from 'react-window'
77
import { ThemeContext } from 'styled-components'
88
import AutoSizer from 'react-virtualized-auto-sizer'
9+
import useI18n from 'hooks/useI18n'
910
import { useActiveWeb3React } from '../../hooks'
1011
import { AppState } from '../../state'
1112
import { useAllTokens, useToken } from '../../hooks/Tokens'
@@ -23,8 +24,6 @@ import { filterTokens } from './filtering'
2324
import SortButton from './SortButton'
2425
import { useTokenComparator } from './sorting'
2526
import { PaddedColumn, SearchInput, Separator } from './styleds'
26-
import TranslatedText from '../TranslatedText'
27-
import { TranslateString } from '../../utils/translateTextHelpers'
2827

2928
interface CurrencySearchProps {
3029
isOpen: boolean
@@ -137,16 +136,16 @@ export function CurrencySearch({
137136
)
138137

139138
const selectedListInfo = useSelectedListInfo()
140-
139+
const TranslateString = useI18n()
141140
return (
142141
<Column style={{ width: '100%', flex: '1 1' }}>
143142
<PaddedColumn gap="14px">
144143
<RowBetween>
145144
<Text>
146-
<TranslatedText translationId={82}>Select a token</TranslatedText>
145+
{TranslateString(82, 'Select a token')}
147146
<QuestionHelper
148147
text={TranslateString(
149-
130,
148+
128,
150149
'Find a token by searching for its name or symbol or by pasting its address below.'
151150
)}
152151
/>
@@ -166,9 +165,7 @@ export function CurrencySearch({
166165
<CommonBases chainId={chainId} onSelect={handleCurrencySelect} selectedCurrency={selectedCurrency} />
167166
)}
168167
<RowBetween>
169-
<Text fontSize="14px">
170-
<TranslatedText translationId={126}>Token name</TranslatedText>
171-
</Text>
168+
<Text fontSize="14px">{TranslateString(126, 'Token name')}</Text>
172169
<SortButton ascending={invertSearchOrder} toggleSortOrder={() => setInvertSearchOrder((iso) => !iso)} />
173170
</RowBetween>
174171
</PaddedColumn>
@@ -213,7 +210,7 @@ export function CurrencySearch({
213210
onClick={onChangeList}
214211
id="currency-search-change-list-button"
215212
>
216-
{selectedListInfo.current ? 'Change' : 'Select a list'}
213+
{selectedListInfo.current ? TranslateString(180, 'Change') : TranslateString(1152, 'Select a list')}
217214
</LinkStyledButton>
218215
</RowBetween>
219216
</Card>

0 commit comments

Comments
 (0)