useflyyer / next-rosetta

Next.js + Rosetta + TypeScript with native i18n support | Lightweight, simple, easy to integrate, no custom server required and efficient because will only download the locale you need.
https://next-rosetta.vercel.app
MIT License
64 stars 4 forks source link

Loading translation in a page with getServerSideProps. #10

Closed Rickk137 closed 3 years ago

Rickk137 commented 3 years ago

It's not possible to have getInitialProps and getServerSideProps in the same page. So how should we load the translation in such a page?

lopezjurip commented 3 years ago

Here is an example with getServerSide props: https://github.com/flayyer/next-rosetta#example-with-getserversideprops

getInitialProps is not recommended anymore but I think you can use it as:

// Untested
Page.getInitialProps = async (context) => {
  const locale = context.locale || context.defaultLocale;
  const { table = {} } = await import(`../i18n/${locale}`); // Import locale
  return { props: { table } }; // Passed to `/pages/_app.tsx`
}