Skip to content

Conversation

yoseph0524
Copy link

No description provided.

Added concise examples for accessing locale info using useRouter, getStaticProps, and getStaticPaths. Reformatted with JSX blocks for consistency with other sections.
Improve locale access examples for i18n routing
@ijjk ijjk added the Documentation Related to Next.js' official documentation. label Oct 7, 2025
Comment on lines +227 to +229
Current locale: {locale}
All locales: {locales?.join(', ')}
Default locale: {defaultLocale}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Current locale: {locale}
All locales: {locales?.join(', ')}
Default locale: {defaultLocale}
<>
<div>Current locale: {locale}</div>
<div>All locales: {locales?.join(', ')}</div>
<div>Default locale: {defaultLocale}</div>
</>

The JSX code example has invalid syntax - the return statement contains text content without wrapping it in a JSX element.

View Details

Analysis

Invalid JSX syntax in internationalization documentation example

What fails: The LocaleExample component in docs/02-pages/02-guides/internationalization.mdx (lines 226-230) has invalid JSX syntax - returns multiple text nodes without a wrapper element

How to reproduce:

cd /tmp && npm install @babel/core @babel/preset-react
node << 'EOF'
const babel = require('@babel/core');
const code = `
export default function LocaleExample() {
  const { locale, locales, defaultLocale } = useRouter();
  return (
      Current locale: {locale}
      All locales: {locales?.join(', ')}
      Default locale: {defaultLocale}
  );
}`;
babel.transformSync(code, { presets: ['@babel/preset-react'] });
EOF

Result: Babel compilation fails with error: Unexpected token, expected "," (7:14) at the "Current locale:" text line

Expected: JSX requires multiple elements/text nodes to be wrapped in a parent element or Fragment per React documentation on Fragments. All other code examples in this file properly wrap content in JSX elements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Related to Next.js' official documentation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants