Commit a7a1607f authored by Moody Salem's avatar Moody Salem Committed by GitHub

fix: add a link to switch the locale conditionally (#1776)

* add a link to switch the locale conditionally

* make it smaller

* add the locale labels

* language labels from the internet

* fix the heart in the claim popup

* undo the conditional change

* remove todo

* updated Chinese locale name to office-365 language ids

* added missing <Trans>
Co-authored-by: default avatarJustin Domingue <judo@uniswap.org>
parent 5125cbb1
import { Trans } from '@lingui/macro'
import { CurrencyAmount, Token } from '@uniswap/sdk-core' import { CurrencyAmount, Token } from '@uniswap/sdk-core'
import React, { useCallback, useEffect } from 'react' import React, { useCallback, useEffect } from 'react'
import ReactGA from 'react-ga' import ReactGA from 'react-ga'
import { X } from 'react-feather' import { Heart, X } from 'react-feather'
import styled, { keyframes } from 'styled-components' import styled, { keyframes } from 'styled-components'
import tokenLogo from '../../assets/images/token-logo.png' import tokenLogo from '../../assets/images/token-logo.png'
import { ButtonPrimary } from '../../components/Button' import { ButtonPrimary } from '../../components/Button'
...@@ -104,18 +105,20 @@ export default function ClaimPopup() { ...@@ -104,18 +105,20 @@ export default function ClaimPopup() {
<span role="img" aria-label="party"> <span role="img" aria-label="party">
🎉 🎉
</span>{' '} </span>{' '}
UNI has arrived{' '} <Trans>UNI has arrived</Trans>{' '}
<span role="img" aria-label="party"> <span role="img" aria-label="party">
🎉 🎉
</span> </span>
</TYPE.white> </TYPE.white>
<TYPE.subHeader style={{ paddingTop: '0.5rem', textAlign: 'center' }} color="white"> <TYPE.subHeader style={{ paddingTop: '0.5rem', textAlign: 'center' }} color="white">
{`Thanks for being part of the Uniswap community <3`} <Trans>
Thanks for being part of the Uniswap community <Heart size={12} />
</Trans>
</TYPE.subHeader> </TYPE.subHeader>
</AutoColumn> </AutoColumn>
<AutoColumn style={{ zIndex: 10 }} justify="center"> <AutoColumn style={{ zIndex: 10 }} justify="center">
<ButtonPrimary padding="8px" borderRadius="8px" width={'fit-content'} onClick={handleToggleSelfClaimModal}> <ButtonPrimary padding="8px" borderRadius="8px" width={'fit-content'} onClick={handleToggleSelfClaimModal}>
Claim your UNI tokens <Trans>Claim your UNI tokens</Trans>
</ButtonPrimary> </ButtonPrimary>
</AutoColumn> </AutoColumn>
</StyledClaimPopup> </StyledClaimPopup>
......
import { Trans } from '@lingui/macro'
import React, { useMemo } from 'react'
import { useLocation } from 'react-router'
import styled from 'styled-components/macro'
import { DEFAULT_LOCALE, LOCALE_LABEL, SupportedLocale } from '../../constants/locales'
import { navigatorLocale, useActiveLocale } from '../../hooks/useActiveLocale'
import useParsedQueryString from '../../hooks/useParsedQueryString'
import { StyledInternalLink, TYPE } from '../../theme'
import { stringify } from 'qs'
const Container = styled(TYPE.small)`
opacity: 0.6;
:hover {
opacity: 1;
}
margin-top: 1rem !important;
`
export function SwitchLocaleLink() {
const activeLocale = useActiveLocale()
const browserLocale = useMemo(() => navigatorLocale(), [])
const location = useLocation()
const qs = useParsedQueryString()
if (browserLocale && (browserLocale !== DEFAULT_LOCALE || activeLocale !== DEFAULT_LOCALE)) {
let targetLocale: SupportedLocale
if (activeLocale === browserLocale) {
targetLocale = DEFAULT_LOCALE
} else {
targetLocale = browserLocale
}
const target = {
...location,
search: stringify({ ...qs, lng: targetLocale }),
}
return (
<Container>
<Trans>
Uniswap available in: {<StyledInternalLink to={target}>{LOCALE_LABEL[targetLocale]}</StyledInternalLink>}
</Trans>
</Container>
)
}
return null
}
...@@ -35,7 +35,36 @@ export type SupportedLocale = typeof SUPPORTED_LOCALES[number] ...@@ -35,7 +35,36 @@ export type SupportedLocale = typeof SUPPORTED_LOCALES[number]
export const DEFAULT_LOCALE: SupportedLocale = 'en-US' export const DEFAULT_LOCALE: SupportedLocale = 'en-US'
// todo: fill this back out export const LOCALE_LABEL: { [locale in SupportedLocale]: string } = {
export const LOCALE_LABEL: { [locale in SupportedLocale]?: string } = { 'af-ZA': 'Afrikaans',
'ar-SA': 'العربية',
'ca-ES': 'Català',
'cs-CZ': 'čeština',
'da-DK': 'dansk',
'de-DE': 'Deutsche',
'el-GR': 'ελληνικά',
'en-US': 'English', 'en-US': 'English',
'es-ES': 'Español',
'fi-FI': 'Suomalainen',
'fr-FR': 'français',
'he-IL': 'עִברִית',
'hu-HU': 'Magyar',
'id-ID': 'bahasa Indonesia',
'it-IT': 'Italiano',
'ja-JP': '日本語',
'ko-KR': '한국어',
'nl-NL': 'Nederlands',
'no-NO': 'norsk',
'pl-PL': 'Polskie',
'pt-BR': 'português',
'pt-PT': 'português',
'ro-RO': 'Română',
'ru-RU': 'русский',
'sr-SP': 'Српски',
'sv-SE': 'svenska',
'tr-TR': 'Türkçe',
'uk-UA': 'Український',
'vi-VN': 'Tiếng Việt',
'zh-CN': '中文 ( 中国 )',
'zh-TW': '中文 ( 台灣 )',
} }
...@@ -17,7 +17,7 @@ function parseLocale(maybeSupportedLocale: string): SupportedLocale | undefined ...@@ -17,7 +17,7 @@ function parseLocale(maybeSupportedLocale: string): SupportedLocale | undefined
/** /**
* Returns the supported locale read from the user agent (navigator) * Returns the supported locale read from the user agent (navigator)
*/ */
function navigatorLocale(): SupportedLocale | undefined { export function navigatorLocale(): SupportedLocale | undefined {
if (!navigator.language) return undefined if (!navigator.language) return undefined
const [language, region] = navigator.language.split('-') const [language, region] = navigator.language.split('-')
......
...@@ -13,6 +13,7 @@ import { Link } from 'react-router-dom' ...@@ -13,6 +13,7 @@ import { Link } from 'react-router-dom'
import { useWalletModalToggle } from 'state/application/hooks' import { useWalletModalToggle } from 'state/application/hooks'
import styled, { ThemeContext } from 'styled-components' import styled, { ThemeContext } from 'styled-components'
import { HideSmall, TYPE } from 'theme' import { HideSmall, TYPE } from 'theme'
import { SwitchLocaleLink } from '../../components/SwitchLocaleLink'
import { LoadingRows } from './styleds' import { LoadingRows } from './styleds'
import Toggle from 'components/Toggle' import Toggle from 'components/Toggle'
import { useUserHideClosedPositions } from 'state/user/hooks' import { useUserHideClosedPositions } from 'state/user/hooks'
...@@ -295,6 +296,7 @@ export default function Pool() { ...@@ -295,6 +296,7 @@ export default function Pool() {
</AutoColumn> </AutoColumn>
</AutoColumn> </AutoColumn>
</PageWrapper> </PageWrapper>
<SwitchLocaleLink />
</> </>
) )
} }
import { Trans } from '@lingui/macro'
import { Currency, CurrencyAmount, Token, TradeType } from '@uniswap/sdk-core' import { Currency, CurrencyAmount, Token, TradeType } from '@uniswap/sdk-core'
import { Trade as V2Trade } from '@uniswap/v2-sdk' import { Trade as V2Trade } from '@uniswap/v2-sdk'
import { Trade as V3Trade } from '@uniswap/v3-sdk' import { Trade as V3Trade } from '@uniswap/v3-sdk'
...@@ -6,7 +7,7 @@ import UnsupportedCurrencyFooter from 'components/swap/UnsupportedCurrencyFooter ...@@ -6,7 +7,7 @@ import UnsupportedCurrencyFooter from 'components/swap/UnsupportedCurrencyFooter
import { MouseoverTooltip, MouseoverTooltipContent } from 'components/Tooltip' import { MouseoverTooltip, MouseoverTooltipContent } from 'components/Tooltip'
import JSBI from 'jsbi' import JSBI from 'jsbi'
import React, { useCallback, useContext, useEffect, useMemo, useState } from 'react' import React, { useCallback, useContext, useEffect, useMemo, useState } from 'react'
import { ArrowDown, CheckCircle, HelpCircle, Info, ArrowLeft } from 'react-feather' import { ArrowDown, ArrowLeft, CheckCircle, HelpCircle, Info } from 'react-feather'
import ReactGA from 'react-ga' import ReactGA from 'react-ga'
import { Link, RouteComponentProps } from 'react-router-dom' import { Link, RouteComponentProps } from 'react-router-dom'
import { Text } from 'rebass' import { Text } from 'rebass'
...@@ -26,8 +27,8 @@ import ConfirmSwapModal from '../../components/swap/ConfirmSwapModal' ...@@ -26,8 +27,8 @@ import ConfirmSwapModal from '../../components/swap/ConfirmSwapModal'
import { ArrowWrapper, BottomGrouping, Dots, SwapCallbackError, Wrapper } from '../../components/swap/styleds' import { ArrowWrapper, BottomGrouping, Dots, SwapCallbackError, Wrapper } from '../../components/swap/styleds'
import SwapHeader from '../../components/swap/SwapHeader' import SwapHeader from '../../components/swap/SwapHeader'
import TradePrice from '../../components/swap/TradePrice' import TradePrice from '../../components/swap/TradePrice'
import { SwitchLocaleLink } from '../../components/SwitchLocaleLink'
import TokenWarningModal from '../../components/TokenWarningModal' import TokenWarningModal from '../../components/TokenWarningModal'
import { useActiveWeb3React } from '../../hooks/web3'
import { useAllTokens, useCurrency } from '../../hooks/Tokens' import { useAllTokens, useCurrency } from '../../hooks/Tokens'
import { ApprovalState, useApproveCallbackFromTrade } from '../../hooks/useApproveCallback' import { ApprovalState, useApproveCallbackFromTrade } from '../../hooks/useApproveCallback'
import { V3TradeState } from '../../hooks/useBestV3Trade' import { V3TradeState } from '../../hooks/useBestV3Trade'
...@@ -39,6 +40,7 @@ import { useSwapCallback } from '../../hooks/useSwapCallback' ...@@ -39,6 +40,7 @@ import { useSwapCallback } from '../../hooks/useSwapCallback'
import useToggledVersion, { Version } from '../../hooks/useToggledVersion' import useToggledVersion, { Version } from '../../hooks/useToggledVersion'
import { useUSDCValue } from '../../hooks/useUSDCPrice' import { useUSDCValue } from '../../hooks/useUSDCPrice'
import useWrapCallback, { WrapType } from '../../hooks/useWrapCallback' import useWrapCallback, { WrapType } from '../../hooks/useWrapCallback'
import { useActiveWeb3React } from '../../hooks/web3'
import { useWalletModalToggle } from '../../state/application/hooks' import { useWalletModalToggle } from '../../state/application/hooks'
import { Field } from '../../state/swap/actions' import { Field } from '../../state/swap/actions'
import { import {
...@@ -55,7 +57,6 @@ import { isTradeBetter } from '../../utils/isTradeBetter' ...@@ -55,7 +57,6 @@ import { isTradeBetter } from '../../utils/isTradeBetter'
import { maxAmountSpend } from '../../utils/maxAmountSpend' import { maxAmountSpend } from '../../utils/maxAmountSpend'
import { warningSeverity } from '../../utils/prices' import { warningSeverity } from '../../utils/prices'
import AppBody from '../AppBody' import AppBody from '../AppBody'
import { Trans } from '@lingui/macro'
const StyledInfo = styled(Info)` const StyledInfo = styled(Info)`
opacity: 0.4; opacity: 0.4;
...@@ -658,6 +659,7 @@ export default function Swap({ history }: RouteComponentProps) { ...@@ -658,6 +659,7 @@ export default function Swap({ history }: RouteComponentProps) {
</AutoColumn> </AutoColumn>
</Wrapper> </Wrapper>
</AppBody> </AppBody>
<SwitchLocaleLink />
{!swapIsUnsupported ? null : ( {!swapIsUnsupported ? null : (
<UnsupportedCurrencyFooter show={swapIsUnsupported} currencies={[currencies.INPUT, currencies.OUTPUT]} /> <UnsupportedCurrencyFooter show={swapIsUnsupported} currencies={[currencies.INPUT, currencies.OUTPUT]} />
)} )}
......
...@@ -14,6 +14,7 @@ import { GreyCard } from '../../components/Card' ...@@ -14,6 +14,7 @@ import { GreyCard } from '../../components/Card'
import { AutoColumn } from '../../components/Column' import { AutoColumn } from '../../components/Column'
import { CardSection, DataCard } from '../../components/earn/styled' import { CardSection, DataCard } from '../../components/earn/styled'
import { RowBetween, RowFixed } from '../../components/Row' import { RowBetween, RowFixed } from '../../components/Row'
import { SwitchLocaleLink } from '../../components/SwitchLocaleLink'
import DelegateModal from '../../components/vote/DelegateModal' import DelegateModal from '../../components/vote/DelegateModal'
import VoteModal from '../../components/vote/VoteModal' import VoteModal from '../../components/vote/VoteModal'
import { import {
...@@ -199,6 +200,7 @@ export default function VotePage({ ...@@ -199,6 +200,7 @@ export default function VotePage({
} }
return ( return (
<>
<PageWrapper gap="lg" justify="center"> <PageWrapper gap="lg" justify="center">
<VoteModal isOpen={showVoteModal} onDismiss={toggleVoteModal} proposalId={proposalData?.id} support={support} /> <VoteModal isOpen={showVoteModal} onDismiss={toggleVoteModal} proposalId={proposalData?.id} support={support} />
<DelegateModal isOpen={showDelegateModal} onDismiss={toggleDelegateModal} title={<Trans>Unlock Votes</Trans>} /> <DelegateModal isOpen={showDelegateModal} onDismiss={toggleDelegateModal} title={<Trans>Unlock Votes</Trans>} />
...@@ -255,7 +257,7 @@ export default function VotePage({ ...@@ -255,7 +257,7 @@ export default function VotePage({
toggleVoteModal() toggleVoteModal()
}} }}
> >
Vote For <Trans>Vote For</Trans>
</ButtonPrimary> </ButtonPrimary>
<ButtonPrimary <ButtonPrimary
padding="8px" padding="8px"
...@@ -355,5 +357,7 @@ export default function VotePage({ ...@@ -355,5 +357,7 @@ export default function VotePage({
</AutoColumn> </AutoColumn>
</ProposalInfo> </ProposalInfo>
</PageWrapper> </PageWrapper>
<SwitchLocaleLink />
</>
) )
} }
import React from 'react' import React from 'react'
import { AutoColumn } from '../../components/Column' import { AutoColumn } from '../../components/Column'
import styled from 'styled-components/macro' import styled from 'styled-components/macro'
import { SwitchLocaleLink } from '../../components/SwitchLocaleLink'
import { UNI } from '../../constants/tokens' import { UNI } from '../../constants/tokens'
import { ExternalLink, TYPE } from '../../theme' import { ExternalLink, TYPE } from '../../theme'
import { RowBetween, RowFixed } from '../../components/Row' import { RowBetween, RowFixed } from '../../components/Row'
...@@ -135,6 +136,7 @@ export default function Vote() { ...@@ -135,6 +136,7 @@ export default function Vote() {
) )
return ( return (
<>
<PageWrapper gap="lg" justify="center"> <PageWrapper gap="lg" justify="center">
<DelegateModal <DelegateModal
isOpen={showDelegateModal} isOpen={showDelegateModal}
...@@ -155,8 +157,8 @@ export default function Vote() { ...@@ -155,8 +157,8 @@ export default function Vote() {
<RowBetween> <RowBetween>
<TYPE.white fontSize={14}> <TYPE.white fontSize={14}>
<Trans> <Trans>
UNI tokens represent voting shares in Uniswap governance. You can vote on each proposal yourself or UNI tokens represent voting shares in Uniswap governance. You can vote on each proposal yourself
delegate your votes to a third party. or delegate your votes to a third party.
</Trans> </Trans>
</TYPE.white> </TYPE.white>
</RowBetween> </RowBetween>
...@@ -260,5 +262,7 @@ export default function Vote() { ...@@ -260,5 +262,7 @@ export default function Vote() {
<Trans>A minimum threshold of 1% of the total UNI supply is required to submit proposals</Trans> <Trans>A minimum threshold of 1% of the total UNI supply is required to submit proposals</Trans>
</TYPE.subHeader> </TYPE.subHeader>
</PageWrapper> </PageWrapper>
<SwitchLocaleLink />
</>
) )
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment