Skip to content

Conversation

@goanpeca
Copy link

@goanpeca goanpeca commented May 1, 2025

Hello, folks!

This PR adds a language switcher and some logic to deal with multiple languages on the xarray website. Using lingui and babel.

Currently, as part of the Scientific Python grant, we have the site 100% translated into Portuguese (Brazilian) and Spanish. Other languages may follow soon - having the infrastructure set up will hopefully help us recruit new translators 😄

We have been working on the automation process for the sync between crowdin and the websites and can help answer any questions you might have.

This PR is a proof of concept and we are happy to adapt to any specific format or needs you might have here. Feedback is appreciated.

Thanks!

Desktop

Screenshot 2025-05-04 at 10 07 13 AM

Mobile

Screenshot 2025-05-04 at 10 11 42 AM

Moving forward

Ensure all translatable strings are wrapped up in the t macro. Yarn build will extract and compile the translations strings

and the rest of the work will happen automatically on https://github.com/Scientific-Python-Translations/xarray-translations and crowding with the volunteer contributors.

For components and pages

import { useLingui } from '@lingui/react/macro'

const Team = () => {
  const { t } = useLingui()
  return ({t`Current core maintainers 🤝`})

For data: convert the object to a function so the t macro can work.

import { useLingui } from '@lingui/react/macro'

export const getLibraries = () => {
  const { t } = useLingui()
  let Libraries = [
    {
      name: 'NumPy',
      description: t`NumPy is the fundamental package for array computing with Python.`,
      url: 'https://numpy.org',
      repo: 'https://github.com/numpy/numpy',
      logo: '/libraries/numpy_logo.svg',
    },
...
}

@vercel
Copy link

vercel bot commented May 1, 2025

@goanpeca is attempting to deploy a commit to the xarray Team on Vercel.

A member of the Team first needs to authorize it.

@goanpeca goanpeca changed the title Add i18n and 10n with lingui and babel WIP: Add i18n and 10n with lingui and babel May 1, 2025
@goanpeca goanpeca force-pushed the add-i18n branch 2 times, most recently from aadbd9f to 405cf9f Compare May 1, 2025 13:08
@melissawm
Copy link

For context, here's some initial discussion around this topic: pydata/xarray#9094

@goanpeca
Copy link
Author

goanpeca commented May 2, 2025

The PR has now selected all localizable strings. I added a simple dropdown but I need some help in getting it to actually change the language.

@goanpeca goanpeca changed the title WIP: Add i18n and 10n with lingui and babel Add i18n and 10n with lingui and babel May 2, 2025
@goanpeca goanpeca marked this pull request as ready for review May 2, 2025 04:25
@goanpeca
Copy link
Author

goanpeca commented May 5, 2025

Hi @andersy005 :)

Wanted to know what we could do to help move this forward

Thanks!

@andersy005
Copy link
Member

thank you for your patience, @goanpeca! very cool to see this addition to the site! let's remove the RSS feed files (atom.xml, rss.json, rss.xml) from git. these aren't meant to be pushed.

@jhamman, i no longer have permissions to approve the vercel deployment. do you mind authorizing it so we can check how it looks in staging? after that, we can merge to prod.

@goanpeca
Copy link
Author

goanpeca commented May 6, 2025

Hi @andersy005 thanks!

Will make the changes and ping you :)

@goanpeca
Copy link
Author

goanpeca commented May 7, 2025

thank you for your patience, @goanpeca! very cool to see this addition to the site! let's remove the RSS feed files (atom.xml, rss.json, rss.xml) from git. these aren't meant to be pushed.

I made the updates @andersy005 ! Thanks 🚀


cc @jhamman 🙈

@goanpeca goanpeca changed the title Add i18n and 10n with lingui and babel Add i18n and l10n with lingui and babel May 7, 2025
Copy link
Member

@andersy005 andersy005 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks solid, @goanpeca! thank you for putting it together. looking forward to other translations

waiting for @jhamman to authorize the preview, when he gets a moment

@vercel
Copy link

vercel bot commented May 8, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
xarray-dev ❌ Failed (Inspect) May 8, 2025 3:01pm

@goanpeca
Copy link
Author

goanpeca commented May 8, 2025

Thanks @jhamman , there seems to be some issue but I cannot access the logs, any pointers to debug this?

Thanks

@jhamman
Copy link
Contributor

jhamman commented May 8, 2025

Here are the logs:

[08:00:55.456] Running build in Washington, D.C., USA (East) – iad1
[08:00:55.482] Cloning github.com/xarray-contrib/xarray.dev (Branch: add-i18n, Commit: a89f645)
[08:00:57.628] Cloning completed: 2.146s
[08:01:00.884] Restored build cache from previous deployment (5tdvhbKSYoayVgx2MA7LLnnudq8u)
[08:01:01.928] Running "vercel build"
[08:01:02.351] Vercel CLI 41.7.3
[08:01:05.911] yarn config v1.22.19
[08:01:05.950] success Set "enableGlobalCache" to "false".
[08:01:05.951] Done in 0.04s.
[08:01:05.960] Installing dependencies...
[08:01:06.152] yarn install v1.22.19
[08:01:06.231] [1/4] Resolving packages...
[08:01:21.212] [2/4] Fetching packages...
[08:01:51.677] error @lingui/[email protected]: The engine "node" is incompatible with this module. Expected version ">=20.0.0". Got "18.20.6"
[08:01:51.689] error Found incompatible module.
[08:01:51.689] info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
[08:01:51.753] Error: Command "yarn install" exited with 1
[08:01:52.336] 
[08:01:55.468] Exiting build container

@andersy005
Copy link
Member

[08:01:51.677] error @lingui/[email protected]: The engine "node" is incompatible with this module. Expected version ">=20.0.0". Got "18.20.6"

@jhamman, can we bump the node version in our vercel settings?

@goanpeca
Copy link
Author

Hi @jhamman and @andersy005, wanted to ask if the vercel configuration could be updated 😄 ?

Thanks! 🚀

@jhamman
Copy link
Contributor

jhamman commented May 29, 2025

I've bumped our node version to 20.x. The (re)deployment ran and reported this error:

 ⨯ ESLint: Invalid Options: - Unknown options: useEslintrc, extensions - 'extensions' has been removed.

@andersy005 - do you have bandwidth this week to help unblock here?

@ianhi
Copy link
Contributor

ianhi commented Oct 29, 2025

Hi,

We've moved to netlfiy and now use node version v20.19.5 which runs without error. So I suspect with a rebase and conflict resolution this will work. @goanpeca are you still interested in working on this? I think this is a valuable thing and would like to help see it through.

@melissawm
Copy link

I can help push this forward - thanks for the ping!

I am traveling at the moment but can take a look probably around Nov 10. Does that work?

@ianhi
Copy link
Contributor

ianhi commented Oct 30, 2025

I am traveling at the moment but can take a look probably around Nov 10. Does that work?

sounds great! I've left a note on my calendar to check back then. Excited to to work to get this in.

@melissawm
Copy link

Thanks for the ping! I'm currently working on the rebase, will ping you once I have it solved. Cheers!

@melissawm
Copy link

Ok! I think I got it but I can't push to this PR - @goanpeca would you mind giving me access to your fork so I can finish this up? Thanks a bunch! 😄

@goanpeca
Copy link
Author

goanpeca commented Nov 19, 2025

would you mind giving me access to your fork so I can finish this up? Thanks a bunch! 😄

Done @melissawm !

Copilot AI review requested due to automatic review settings November 19, 2025 14:57
@netlify
Copy link

netlify bot commented Nov 19, 2025

Deploy Preview for xarraydev ready!

Name Link
🔨 Latest commit 6e2ccea
🔍 Latest deploy log https://app.netlify.com/projects/xarraydev/deploys/6922095eadbced0008eb4621
😎 Deploy Preview https://deploy-preview-772--xarraydev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copilot finished reviewing on behalf of melissawm November 19, 2025 14:58
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds internationalization (i18n) and localization (l10n) infrastructure to the xarray website using Lingui and Babel. The site is currently translated into Portuguese (Brazilian) and Spanish, with the framework in place for additional languages.

Key changes:

  • Integration of Lingui for message extraction and translation management
  • Addition of language switcher component for users to select their preferred language
  • Conversion of static strings to translatable strings using the t macro throughout the codebase

Reviewed Changes

Copilot reviewed 35 out of 37 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
yarn.lock Added Lingui packages (@lingui/cli, @lingui/core, @lingui/react, @lingui/loader, @lingui/babel-plugin-lingui-macro) and updated various dependencies
src/i18n.ts Created i18n initialization logic and catalog loading functionality
src/pages/_app.js Wrapped app with I18nProvider and added translation loading via useLinguiInit
src/locales/pt/messages.po Added Portuguese (Brazilian) translations
src/locales/es/messages.po Added Spanish translations
src/pages/index.js Added getStaticProps for translation loading and wrapped strings with t macro
src/pages/team.js Wrapped translatable strings with t macro
src/pages/dashboard.js Wrapped translatable strings with t macro
src/data/projects.js Converted from static export to function returning translated data
src/data/menu-items.js Converted from static export to function returning translated data
src/data/footer-items.js Converted from static export to function returning translated data
src/data/features.js Converted from static export to function returning translated data
src/components/sponsors.js Wrapped translatable strings with t macro

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

*/
const { t } = useLingui()
const router = useRouter()
const { pathname, asPath, query } = router
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused variable asPath.

Suggested change
const { pathname, asPath, query } = router
const { pathname, query } = router

Copilot uses AI. Check for mistakes.
*/
const { t } = useLingui()
const router = useRouter()
const { pathname, asPath, query } = router
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused variable query.

Suggested change
const { pathname, asPath, query } = router

Copilot uses AI. Check for mistakes.
@@ -1,12 +1,14 @@
import { IssueTracker, ProjectMetrics } from '@/components/dashboard'
import { Layout } from '@/components/layout'
import { Trans, useLingui } from '@lingui/react/macro'
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import Trans.

Copilot uses AI. Check for mistakes.
@melissawm
Copy link

Thank you @goanpeca ❤️ ❤️

I will take a look at the copilot review and try to address it shortly.

Copy link
Contributor

@ianhi ianhi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to have broken the display of blog articles. The listing of them is still fine (although only avaiable in english) but the actual articles are giving me a 500 error:

https://deploy-preview-772--xarraydev.netlify.app/es/blog/xarray-napari-plan

that happens with or without the language code in the url

@ianhi
Copy link
Contributor

ianhi commented Nov 19, 2025

Also, what would be the steps after this PR for someone who wanted to make a change to the wording on the site. Would they only need to change the english version in the code, or do they also need to do things on the translation website and update the .po files?

We should include the documentation of how to do so in the README

@melissawm
Copy link

Hmmm let me check - I did test the blog locally and it worked, but it may be something else.

@ianhi
Copy link
Contributor

ianhi commented Nov 19, 2025

One more thing. On this PR, but not on main, npm install fails for me with the following error (yarn install works)

npm error code ERESOLVE
npm error ERESOLVE unable to resolve dependency tree
npm error
npm error While resolving: [email protected]
npm error Found: [email protected]
npm error node_modules/apexcharts
npm error   apexcharts@"3.54.0" from the root project
npm error
npm error Could not resolve dependency:
npm error peer apexcharts@">=4.0.0" from [email protected]
npm error node_modules/react-apexcharts
npm error   react-apexcharts@"^1.8.0" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.
npm error
npm error
npm error For a full report see:
npm error /Users/ian/.npm/_logs/2025-11-19T16_15_56_681Z-eresolve-report.txt
npm error A complete log of this run can be found in: /Users/ian/.npm/_logs/2025-11-19T16_15_56_681Z-debug-0.log

@melissawm
Copy link

melissawm commented Nov 22, 2025

Ok - I tried solving the npm issues and I can confirm it builds without error for me with both npm and yarn. The blog also works fine for me locally, although I did see it fail on the netlify deployment. Not sure what's going on there... This PR doesn't touch the blog at all so I will have to think about how to debug this.

I also realized it looks like I requested a copilot review but I in fact didn't (not explicitly, anyways) so I tried addressing the issues (which were mostly fair) but not sure if there's anything else I can do there.

I will work on some documentation but right now we have it all set up so that translations will not come through this repo at all. All the translation work happens on scientific-python.crowdin.com (see https://github.com/Scientific-Python-Translations/xarray-translations), and gets synced through one PR from the scientificpythontranslations bot when new translations are created. We have some documentation here but I'm happy to add a note explaining it all to your docs as well.

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants