Skip to content

Commit 315c487

Browse files
goanpecamelissawmCopilotpre-commit-ci[bot]
authored
Add i18n and l10n with lingui and babel (#772)
* Add i18n and 10n with lingui and babel * Adapt strings for localization * Update language switcher * Add local storage and fix language switcher * Add more strings, fix language swithcer routing and add more translations * Add additional strings * remove uneeded router * Add unique key to menuitems * Remove files from version control * Remoe other file and update gititnore and package.json * Remove comment * Fix translations in blog * Try to resolve dependency issues in npm * Apply suggestions from Copilot code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove unused Trans * Add information about translations to README.md * Trying to fix blog display * Add link * Update yarn.lock * Add compiled messages for babel * Apply code review suggestion * Update dependencies * Revert changes to yarn.lock * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Resolve eslint log error * Set default locale for blog posts * First try * Always serve english versions of blog posts * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update packages * Add compile script for lingui * Remove language switcher from blog * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Adjust header elements fit --------- Co-authored-by: Melissa Weber Mendonça <melissawm@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 5f44c00 commit 315c487

42 files changed

Lines changed: 3053 additions & 755 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.babelrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"presets": [
3+
"next/babel"
4+
],
5+
"plugins": ["@lingui/babel-plugin-lingui-macro"]
6+
}

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,12 @@ yarn-error.log*
4747

4848
.yarn
4949
.vscode/
50+
51+
# Lingui
52+
src/locales/**/*.mo
53+
src/locales/**/*.js
54+
55+
# RSS
56+
atom.xml
57+
rss.json
58+
rss.xml

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ You can start editing the page by modifying `pages/index.js`. The page auto-upda
5151
/>
5252
</a>
5353

54+
## Translations
55+
56+
Translations are managed through Crowdin at https://scientific-python.crowdin.com. The xarray project is part of the [Scientific Python](https://scientific-python.org/) organization on Crowdin, which also includes projects such as NumPy, SciPy, and others.
57+
58+
When creating new content or editing existing content, only the english version of the content should be modified directly in this repository. Once this new content is merged into the main branch of the xarray.dev website, the Crowdin integration will automatically pick up the changes and notify translators that new translations are needed. Once the translation is completed, a pull request will be automatically created in this repository to add the new translated content.
59+
60+
For more details on how the integration works, see https://scientific-python-translations.github.io/docs/. For more details on how to translate the website, see https://scientific-python-translations.github.io/translate/.
61+
5462
## Authoring blog post tips
5563

5664
1. To create a new blog post a good place to start is copying a subfolder under `src/posts/`, so, for example https://xarray.dev/blog/flox is written here https://github.com/xarray-contrib/xarray.dev/blob/e04905f5ea039eb2eb848c0b4945beee323900e4/src/posts/flox/index.md

lingui.config.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const nextConfig = require('./next.config')
2+
3+
/** @type {import('@lingui/conf').LinguiConfig} */
4+
module.exports = {
5+
locales: nextConfig.i18n.locales,
6+
pseudoLocale: 'pseudo',
7+
sourceLocale: nextConfig.i18n.defaultLocale,
8+
fallbackLocales: {
9+
default: 'en',
10+
},
11+
catalogs: [
12+
{
13+
path: 'src/locales/{locale}/messages',
14+
include: ['src/'],
15+
},
16+
],
17+
}

next.config.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import nextMDX from "@next/mdx"
22
import rehypeSlug from "rehype-slug"
3+
import { i18nConfig } from "./src/config/i18n.mjs"
34

45
const withMDX = nextMDX({
56
extension: /\.mdx?$/,
@@ -18,4 +19,6 @@ export default withMDX({
1819
images: {
1920
domains: ["raw.githubusercontent.com", "numpy.org", "dask.org", "chainer.org", ],
2021
},
22+
// Available locales for the application
23+
i18n: i18nConfig,
2124
})

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"dev": "next dev",
88
"build": "next build",
99
"start": "next start",
10-
"lint": "next lint"
10+
"lint": "next lint",
11+
"compile": "lingui compile"
1112
},
1213
"repository": {
1314
"type": "git",
@@ -24,6 +25,9 @@
2425
"@emotion/styled": "^11.13.0",
2526
"@fontsource-variable/inter": "^5.2.5",
2627
"@giscus/react": "^3.0.0",
28+
"@lingui/babel-plugin-lingui-macro": "^5.9.0",
29+
"@lingui/loader": "^5.9.0",
30+
"@lingui/react": "^5.9.0",
2731
"@mdx-js/loader": "^3.0.1",
2832
"@mdx-js/react": "^3.0.1",
2933
"@next/mdx": "^14.2.14",

src/components/array-libraries.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import React from 'react'
33
import { IoIosGlobe, IoLogoGithub } from 'react-icons/io'
44

55
import { Image } from '@/components/mdx'
6-
import { Libraries as data } from '@/data/array-libraries'
6+
import { getLibraries } from '@/data/array-libraries'
77

88
import { SocialLink } from '@/components/social-link'
9+
import { useLingui } from '@lingui/react/macro'
910

1011
const Library = ({ name, description, repo, url, logo }) => {
1112
return (
@@ -41,12 +42,13 @@ const Library = ({ name, description, repo, url, logo }) => {
4142
}
4243

4344
export const ArrayLibraries = () => {
45+
const { t } = useLingui()
46+
let data = getLibraries()
4447
const libraries = React.useMemo(() => data, [])
4548
return (
4649
<Box my={8}>
4750
<Text fontSize={'lg'}>
48-
Xarray supports multiple array backends, allowing users to choose array
49-
types that work best for their application.
51+
{t`Xarray supports multiple array backends, allowing users to choose array types that work best for their application.`}
5052
</Text>
5153

5254
<SimpleGrid

src/components/dashboard/issue-tracker.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,27 @@ import { GiDuration } from 'react-icons/gi'
44
import { TimelinePlotContainer } from '@/components/dashboard/timeline-plot-container'
55
import { TimeseriesAggStatsCard } from '@/components/dashboard/timeseries-agg-stats-card'
66
import { Heading } from '@/components/mdx'
7+
import { useLingui } from '@lingui/react/macro'
78

89
export const IssueTracker = () => {
10+
const { t } = useLingui()
911
return (
1012
<Box as='section' id='issue-tracker'>
1113
<Container maxW='container.lg'>
1214
<Heading as='h2' size='xl' textAlign={'center'}>
13-
Xarray Issue Tracker
15+
{t`Xarray Issue Tracker`}
1416
</Heading>
1517
<SimpleGrid columns={{ base: 1, md: 2 }} spacing={{ base: 5, lg: 8 }}>
1618
{' '}
1719
<TimeseriesAggStatsCard
18-
title={'Median time a pull request is open'}
20+
title={t`Median time a pull request is open`}
1921
query={
2022
'https://xarray-datasette.fly.dev/github.json?_shape=array&&sql=select%0D%0A++id%2C%0D%0A++number%2C%0D%0A++state%2C%0D%0A++created_at%2C%0D%0A++closed_at%2C%0D%0A++julianday%28closed_at%29+-+julianday%28created_at%29+as+age_in_days%0D%0Afrom%0D%0A++issues+as+data%0D%0Awhere%0D%0A++type+%3D+%27pull%27%0D%0A++and+state+%3D+%27closed%27%0D%0Aorder+by%0D%0A++id'
2123
}
2224
icon={<GiDuration size={'3em'} />}
2325
/>
2426
<TimeseriesAggStatsCard
25-
title={'Median time an issue is open'}
27+
title={t`Median time an issue is open`}
2628
icon={<GiDuration size={'3em'} />}
2729
query={
2830
'https://xarray-datasette.fly.dev/github.json?_shape=array&&sql=select%0D%0A++id%2C%0D%0A++number%2C%0D%0A++state%2C%0D%0A++created_at%2C%0D%0A++closed_at%2C%0D%0A++julianday%28closed_at%29+-+julianday%28created_at%29+as+age_in_days%0D%0Afrom%0D%0A++issues+as+data%0D%0Awhere%0D%0A++type+%3D+%27issue%27%0D%0A++and+state+%3D+%27closed%27%0D%0Aorder+by%0D%0A++id'

src/components/dashboard/project-metrics.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ import { fetcher } from '@/lib/data-fetching'
55
import { Box, Container, SimpleGrid, Spinner } from '@chakra-ui/react'
66
import { BsPeople, BsPerson } from 'react-icons/bs'
77
import { GoBook, GoPackage, GoStar, GoTag } from 'react-icons/go'
8+
import { useLingui } from '@lingui/react/macro'
89
import useSWR from 'swr'
910

1011
export const ProjectMetrics = () => {
1112
const { data, error } = useSWR(
1213
'https://raw.githubusercontent.com/andersy005/xarray-datasette/a73704d803350a2ec059bec1b4cce601cd9efdd9/data/docs-monthly-views.json',
1314
fetcher,
1415
)
15-
16-
if (error) return <div>failed to load data</div>
16+
const { t } = useLingui()
17+
if (error) return <div>{t`failed to load data`}</div>
1718
if (!data)
1819
return (
1920
<Spinner
@@ -36,17 +37,17 @@ export const ProjectMetrics = () => {
3637
<Container maxW='container.lg'>
3738
{' '}
3839
<Heading as='h2' size='xl' textAlign={'center'}>
39-
Xarray Project Metrics
40+
{t`Xarray Project Metrics`}
4041
</Heading>
4142
<SimpleGrid columns={{ base: 1, md: 3 }} spacing={{ base: 5, lg: 8 }}>
4243
<StatisticsCard
43-
title={'Core Maintainers'}
44+
title={t`Core Maintainers`}
4445
stat={'15'}
4546
icon={<BsPerson size={'3em'} />}
4647
link={'https://docs.xarray.dev/en/stable/team.html'}
4748
/>
4849
<DatasetteStatsCard
49-
title={'Contributors'}
50+
title={t`Contributors`}
5051
query={
5152
'https://xarray-datasette.fly.dev/github/_analyze_tables_/contributors,user_id.json?_shape=array'
5253
}
@@ -55,7 +56,7 @@ export const ProjectMetrics = () => {
5556
/>
5657

5758
<DatasetteStatsCard
58-
title={'Stargazers'}
59+
title={t`Stargazers`}
5960
icon={<GoStar size={'3em'} />}
6061
query={
6162
'https://xarray-datasette.fly.dev/github/_analyze_tables_/stars,user.json?_shape=array'
@@ -64,20 +65,20 @@ export const ProjectMetrics = () => {
6465
/>
6566

6667
<StatisticsCard
67-
title={'Dependent Packages/Repos'}
68+
title={t`Dependent Packages/Repos`}
6869
stat={21275}
6970
icon={<GoPackage size={'3em'} />}
7071
link={'https://github.com/pydata/xarray/network/dependents'}
7172
/>
7273

7374
<StatisticsCard
74-
title={`${month}/${year} Docs Visitors`}
75+
title={t`Docs Visitors` + ` - ${month}/${year}`}
7576
stat={monthlyViews.users}
7677
icon={<GoBook size={'3em'} />}
7778
/>
7879

7980
<DatasetteStatsCard
80-
title={'Releases'}
81+
title={t`Releases`}
8182
query={
8283
'https://xarray-datasette.fly.dev/github/_analyze_tables_/releases,id.json?_shape=array'
8384
}

src/components/dashboard/timeline-plot-container.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
Tabs,
1111
Text,
1212
} from '@chakra-ui/react'
13+
import { useLingui } from '@lingui/react/macro'
1314
import * as d3 from 'd3'
1415
import useSWR from 'swr'
1516

@@ -18,8 +19,8 @@ export const TimelinePlotContainer = () => {
1819
'https://pydata-datasette.fly.dev/open_pulls_and_issues.json?_shape=array&&sql=select%0D%0A++time%2C%0D%0A++open_issues%2C%0D%0A++open_pull_requests%0D%0Afrom%0D%0A++open_pulls_and_issues%0D%0Awhere%0D%0A++project+%3D+%27pydata%2Fxarray%27%0D%0Aorder+by%0D%0A++time',
1920
fetcher,
2021
)
21-
22-
if (error) return <div>failed to load data</div>
22+
const { t } = useLingui()
23+
if (error) return <div>{t`failed to load data`}</div>
2324
if (!data)
2425
return (
2526
<Spinner
@@ -37,16 +38,15 @@ export const TimelinePlotContainer = () => {
3738
return (
3839
<Box my={8}>
3940
<Text fontSize={'md'} align={'center'}>
40-
This is a timeline of how many open issues and pull requests Xarray has
41-
on Github over time from {new Date(start).toLocaleDateString()} to{' '}
41+
{t`This is a timeline of how many open issues and pull requests Xarray has on Github over time from ${new Date(start).toLocaleDateString()} to `}
4242
{new Date(end).toLocaleDateString()}.
4343
</Text>
4444
<br />
4545
<br />
4646
<Tabs align='center' variant='enclosed' isFitted colorScheme='teal'>
4747
<TabList>
4848
<Tab _selected={{ color: 'white', bg: 'teal.500' }}>
49-
Pull Requests
49+
{t`Pull Requests`}
5050
</Tab>
5151
<Tab _selected={{ color: 'white', bg: 'teal.500' }}>Issues</Tab>
5252
</TabList>

0 commit comments

Comments
 (0)