Skip to content

Commit d40df96

Browse files
committed
Add local storage and fix language switcher
1 parent 72d7571 commit d40df96

File tree

14 files changed

+283
-187
lines changed

14 files changed

+283
-187
lines changed

public/atom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<feed xmlns="http://www.w3.org/2005/Atom">
33
<id>https://xarray.dev/blog</id>
44
<title>Xarray Blog Feed</title>
5-
<updated>2025-05-02T04:24:09.201Z</updated>
5+
<updated>2025-05-03T18:37:55.874Z</updated>
66
<generator>https://github.com/jpmonette/feed</generator>
77
<link rel="alternate" href="https://xarray.dev/blog"/>
88
<link rel="self" href="https://xarray.dev/atom.xml"/>

public/rss.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<title>Xarray Blog Feed</title>
55
<link>https://xarray.dev/blog</link>
66
<description>The latest news, insights, and practices about Xarray from the Xarray team</description>
7-
<lastBuildDate>Fri, 02 May 2025 04:24:09 GMT</lastBuildDate>
7+
<lastBuildDate>Sat, 03 May 2025 18:37:55 GMT</lastBuildDate>
88
<docs>https://validator.w3.org/feed/docs/rss2.html</docs>
99
<generator>https://github.com/jpmonette/feed</generator>
1010
<language>en</language>

src/components/dashboard/timeseries-agg-stats-card.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Spinner, Text } from '@chakra-ui/react'
44
import * as d3 from 'd3'
55
import { isWithinInterval, lastDayOfMonth, startOfMonth } from 'date-fns'
66
import useSWR from 'swr'
7+
import { useLingui } from '@lingui/react/macro'
78

89
export const TimeseriesAggStatsCard = ({ query, title, icon }) => {
910
let { data, error } = useSWR(query, fetcher)

src/components/donate.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,18 @@ export const Donate = () => {
3737
position={'relative'}
3838
>
3939
<Text fontSize={'lg'}>
40-
{t`Xarray is a Sponsored Project of NumFOCUS, a `}
40+
{t`Xarray is a NumFOCUS Sponsored Project, a `}
4141
<Text
4242
as={Link}
4343
href={'https://en.wikipedia.org/wiki/501(c)(3)_organization'}
4444
color={'blue.400'}
4545
useExternalIcon
4646
>
47-
{t`501(c)(3) nonprofit charity`}
47+
501(c)(3) nonprofit charity
4848
</Text>{' '}
4949
{t`in the United States. NumFOCUS provides Xarray with fiscal, legal,
5050
and administrative support to help ensure the health and
51-
sustainability of the project. Visit `}
51+
sustainability of the project. For more information, visit `}
5252
<Text
5353
as={Link}
5454
useExternalIcon
@@ -57,7 +57,6 @@ export const Donate = () => {
5757
>
5858
numfocus.org
5959
</Text>{' '}
60-
{t`for more information.`}
6160
<br />
6261
<br />
6362
{t`If you like Xarray and want to support our mission, please consider making a donation to support our efforts.`}

src/components/header.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ import React from 'react'
1919
import { LanguageSwitcher } from './language-switcher'
2020

2121
export const Header = () => {
22-
let menuItems = getMenuItems()
23-
const navItems = React.useMemo(() => menuItems, [])
24-
22+
let navItems = getMenuItems()
2523
const { isOpen, onToggle } = useDisclosure()
2624
const { colorMode, toggleColorMode } = useColorMode()
2725

src/components/language-switcher.js

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,40 @@
1+
'use client'
12
import { Select } from '@chakra-ui/react'
23
import { useLingui } from '@lingui/react/macro'
3-
import { i18n } from "@lingui/core";
4-
import { useRouter } from 'next/navigation'
4+
import { i18n } from '@lingui/core'
5+
import { useRouter, usePathname } from 'next/navigation'
6+
import { useState, useEffect } from 'react'
57

68
export const LanguageSwitcher = () => {
79
const { t } = useLingui()
10+
const router = useRouter()
11+
const pathname = usePathname()
12+
const [selectedValue, setSelectedValue] = useState('')
813

9-
async function dynamicActivate(event) {
10-
const locale = event.target.value
11-
const catalog = await import(`../locales/${locale}/messages.js`)
12-
i18n.load(locale, catalog.messages);
13-
i18n.activate(locale);
14+
async function changeLocale(event) {
15+
const localeString = event.target.value
16+
setSelectedValue(localeString)
17+
localStorage.setItem('locale', localeString)
18+
const catalog = await import(`../locales/${localeString}/messages.js`)
19+
i18n.load(localeString, catalog.messages)
20+
i18n.activate(localeString)
21+
router.push(pathname, { locale: localeString })
1422
}
23+
24+
useEffect(() => {
25+
const storedLocale = localStorage.getItem('locale')
26+
if (storedLocale && storedLocale !== router.locale) {
27+
changeLocale({ target: { value: storedLocale } })
28+
}
29+
}, [])
1530
return (
16-
<Select variant='flushed' size='xs' defaultValue="en" onChange={dynamicActivate}>
31+
<Select
32+
name='selectedLocale'
33+
variant='flushed'
34+
size='xs'
35+
value={selectedValue}
36+
onChange={changeLocale}
37+
>
1738
<option value='en'>{t`English`}</option>
1839
<option value='es'>{t`Spanish`}</option>
1940
<option value='pt'>{t`Portuguese`}</option>

src/components/layout.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Header } from '@/components/header'
44
import { Link } from '@/components/mdx'
55
import { Box, Flex } from '@chakra-ui/react'
66
import Head from 'next/head'
7-
import { Trans, useLingui } from '@lingui/react/macro'
7+
import { useLingui } from '@lingui/react/macro'
88
import { useRouter } from 'next/router'
99

1010
export const Layout = ({
@@ -79,7 +79,6 @@ export const Layout = ({
7979
)}
8080
{children}
8181
</Box>
82-
8382
<Footer />
8483
</Flex>
8584
</>

src/components/mobile-nav.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export const MobileNav = ({ navItems, isOpen }) => {
9898
{navItems.map((navItem) => (
9999
<MobileNavItem key={navItem.label} {...navItem} />
100100
))}
101+
<LanguageSwitcher></LanguageSwitcher>
101102
</Stack>
102103
)
103104
}

src/locales/en/messages.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)