forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocaleSwitcher.js
More file actions
63 lines (61 loc) · 1.53 KB
/
LocaleSwitcher.js
File metadata and controls
63 lines (61 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import React from 'react'
import { useLingui } from '@lingui/react'
import { locales, activate } from './i18n.config'
import svgGlobe from './images/vector-globe.svg'
import { Box, PseudoBox, VisuallyHidden, Image } from '@chakra-ui/core'
const Toggler = (props) => {
const { locale } = props // eslint-disable-line
return (
<PseudoBox
as="button"
key={locale}
padding={0}
onClick={() => activate(locale)}
_focus={{
outline: `3px solid accent`,
}}
bg="primary"
color="#fff"
>
<VisuallyHidden>{locales[locale]}</VisuallyHidden>
<PseudoBox
aria-hidden
fontSize="sm"
pl={2}
py={1}
textTransform="uppercase"
d={{ base: 'none', md: 'flex' }}
alignItems="center"
justifyContent="center"
_hover={{ color:"accent", border:"1px solid", borderColor:"accent" }}
>
{locales[locale]}
<Image
src={ svgGlobe }
px={2}
alt={('SVG Globe')}
/>
</PseudoBox>
<PseudoBox
aria-hidden
d={{ base: 'flex', md: 'none' }}
bg="gray.100"
textTransform="uppercase"
size={10}
alignItems="center"
justifyContent="center"
>
{locale}
</PseudoBox>
</PseudoBox>
)
}
export function LocaleSwitcher() {
const { i18n } = useLingui()
return (
<Box>
{i18n.locale === 'en' && <Toggler locale="fr" />}
{i18n.locale === 'fr' && <Toggler locale="en" />}
</Box>
)
}