Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i18n _meta.en.json tags is resulting in 404 pages #3139

Open
samyakb opened this issue Aug 23, 2024 · 3 comments
Open

i18n _meta.en.json tags is resulting in 404 pages #3139

samyakb opened this issue Aug 23, 2024 · 3 comments

Comments

@samyakb
Copy link

samyakb commented Aug 23, 2024

I am trying to add Nextra docs on subroute with i18n support, but the _meta.en.json or _meta.es.json is not getting picked up by nextra.

My next config is

const withNextra = require("nextra")({  
  theme: "nextra-theme-docs",  
  themeConfig: "./src/theme.config.jsx",  
  i18n: {  
   locales: ["en", "es"],  
   defaultLocale: "en",  
   localeDetection: false,  
  },  
});

module.exports = withNextra(nextConfig);

My middleware code is

// middleware.ts

export const middleware = async (request) => {
// ...REDACTED
const pathnameIsMissingLocale: boolean = SUPPORTED_LOCALES.every(  
  (locale) => !pathname.startsWith(`/${locale}/`) && pathname !== `/${locale}`  
);  
  
if (pathnameIsMissingLocale) {  
  const locale = getLocale(request);  
  return NextResponse.redirect(  
   new URL(search ? `/${locale}/${pathname}${search}` : `/${locale}/${pathname}`, request.url)  
  );  
}
}

The middleware adds the locale and redirects the path if locale does not exist in path.

The _meta.en.json under Pages directory is like this

{  
    "index": {  
       "title": "Documentation",  
       "type": "page",  
       "href": "/docs"  
    },  
    "frameworks": {  
       "title": "Frameworks",  
       "type": "page",  
       "href": "/docs/frameworks"  
    },  
    "faqs": {  
       "title": "FAQs",  
       "type": "page",  
       "href": "/docs/faqs"  
    }  
}

And the

{  
    "index": {  
       "title": "Documentation Spanish",  
       "type": "page",  
       "href": "/docs"  
    },  
    "frameworks": {  
       "title": "Frameworks Spanish",  
       "type": "page",  
       "href": "/docs/frameworks"  
    },  
    "faqs": {  
       "title": "FAQs Spanish",  
       "type": "page",  
       "href": "/docs/faqs"  
    }  
}

But I am getting 404 page for /en/docs and /es/docs

The pages directory tree is this

src/pages/
├── [lang]
│   └── docs
│       ├── faqs.en.mdx
│       ├── faqs.es.mdx
│       ├── frameworks.en.mdx
│       ├── frameworks.es.mdx
│       ├── frameworks.mdx
│       ├── index.en.mdx
│       └── index.es.mdx
├── _meta.en.json
└── _meta.es.json

Am I doing anything wrong here ?

@samyakb
Copy link
Author

samyakb commented Aug 23, 2024

Is this related to this PR ?

ignore loading pageMap for dynamic locale /[locale]

@samyakb
Copy link
Author

samyakb commented Aug 26, 2024

I am using Nextra versions

"nextra": "^2.13.4",
"nextra-theme-docs": "^2.13.4",

After following the v2 Example, I am still getting 404 pages.

This is the directory structure I used, changed to locale to use en-US than en, but en also didnt work.



src/pages
├── docs
│   ├── faqs.en-US.mdx
│   ├── frameworks.en-US.mdx
│   └── index.en-US.mdx
└── _meta.en-US.json

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

No branches or pull requests

2 participants