Skip to content

feat: Preserve locale with cookie & react-intl#58

Open
canerakdas wants to merge 3 commits intonodejs:mainfrom
canerakdas:feat/preserve-locale-with-cookie
Open

feat: Preserve locale with cookie & react-intl#58
canerakdas wants to merge 3 commits intonodejs:mainfrom
canerakdas:feat/preserve-locale-with-cookie

Conversation

@canerakdas
Copy link
Copy Markdown
Member

This PR aims to preserve the current language across navigation between nodejs.org and learn pages if the NEXT_LOCALE cookie is present.

Copilot AI review requested due to automatic review settings April 23, 2026 17:36
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 23, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
nodejs-learn Ready Ready Preview Apr 23, 2026 6:01pm

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 23, 2026

PR Summary

Medium Risk
Moderate risk because it changes global layout context and rewrites top-nav links based on the NEXT_LOCALE cookie/react-intl locale, which could impact navigation paths and SSR/client consistency.

Overview
Adds locale awareness to the site by wrapping the main Layout in a new LocaleProvider (using react-intl) that detects the active locale from the NEXT_LOCALE cookie with a fallback to site.json’s new defaultLocale.

Updates the top navigation to derive navItems from the current react-intl locale and rewrite links via new localizeLink, and adjusts site.json navigation entries to be locale-prefixed (e.g. /en/...). Also introduces the react-intl dependency (and lockfile updates).

Reviewed by Cursor Bugbot for commit 56616b9. Bugbot is set up for automated code reviews on this repo. Configure here.

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 2c817f8. Configure here.

Comment thread util/link.js Outdated
Copy link
Copy Markdown

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

Adds client-side locale detection (via NEXT_LOCALE) and uses it to localize navigation links from the Learn site back to locale-prefixed nodejs.org routes.

Changes:

  • Introduces a LocaleProvider (react-intl IntlProvider) that detects locale from the NEXT_LOCALE cookie.
  • Adds a link-localization utility and updates the navigation component to rewrite locale-prefixed links.
  • Updates site.json navigation entries to include the default locale prefix and adds react-intl as a dependency.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
util/link.js New helper to rewrite locale-prefixed internal links.
providers/LocaleProvider.jsx New provider to source locale from NEXT_LOCALE and expose it via react-intl.
components/Navigation/index.jsx Uses detected locale to localize nav item links.
components/Layout/index.jsx Wraps page layout with LocaleProvider.
site.json Adds defaultLocale and updates nav links to include /en/ prefixes.
package.json Adds react-intl dependency.
package-lock.json Locks new react-intl and related FormatJS dependencies.

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

Comment thread components/Navigation/index.jsx
Comment thread util/link.js Outdated
Comment thread providers/LocaleProvider.jsx
Comment thread util/link.js
Comment thread util/link.js
import MetaBar from '../Metabar';
import SideBar from '../Sidebar';
import Footer from '../Footer';
import LocaleProvider from '../../providers/LocaleProvider';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: providers folder inside components folder.

const [navigationItems, setNavigationItems] = useState(navigation);
const { locale } = useIntl();

useEffect(() => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need to use an useEffect here? Can't this be an useMemo?

Comment thread util/link.js
* @param {string|null} locale - The locale to apply to the link.
* @returns {string} - The localized link.
*/
export const localizeLink = (link, locale) => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I believe react-intl has utils for localizing a link.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's one of the intentions behind using react-intl, is to have it localizing a link for you. Although I'm not seeing now within react-intl a way of doing so. 🤔

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't think such a feature exists 🙈 It seems like we're currently only using a provider that stores the locale. To be honest, I'm not sure there’s much benefit to using it this way 🥲

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does react-intl increase our bundle a lot?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, I chatted with @canerakdas in DMs he's going to pivot without react-intl.

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.

4 participants