Skip to content

Can't access locale files in public directory from nested routes using getServerSideProps #359

Closed
@hrahimi270

Description

@hrahimi270

Describe the bug
I'm using the built-in feature of internationalization of Nextjs. I don't want to use other third-party modules for translations of my app.
So I decided to put my translations in /public/locales and access them using getServerSideProps for dynamic pages and getStaticProps for static pages.
Static pages work fine. But dynamic pages not working and they are not able to access the file using getServerSideProps.
This is the error I have on netlify:

Screen Shot 2021-05-30 at 12 11 25 PM

Also, I'm trying to get my translations simply by this lines of codes in both pages:

const dir = path.resolve('./public/locales')
const filePath = `${dir}/${locale}.json`;
const buffer = fs.readFileSync(filePath);
const translations = JSON.parse(buffer.toString());

Expected behavior
Have my translations in both Static and Dynamic pages.

Versions

  • Next.js: 10.2.0
  • @netlify/plugin-nextjs: 3.3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions