Next.js Discord

Discord Forum

How to use Server Side Rendering (SSR) with next-i18n in a App-router-based setup?

Unanswered
Chinese Alligator posted this in #help-forum
Open in Discord
Chinese AlligatorOP
I got Server Side Rendering working on a Page-router-based setup, but with app-router, I am not allowed to use getStaticProps.

Therefore I cannot invoke this:

import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
import Config from "../next-i18next.config.mjs"

export async function getStaticProps({ locale }: { locale: string }) {
  return {
    props: {
      ...(await serverSideTranslations(locale, undefined, Config)),
    },
  };
}


Therefore, I still need to prefix my page components with 'use client'.

Is there any way to do server side translations in app-based routers?

6 Replies

Chinese AlligatorOP
But that'd mean I either have to do server-side translations, or client-side, correct? I cannot initially load the server-side ones and update them client-side when switching language client-side, correct?
@Chinese Alligator But that'd mean I either have to do server-side translations, or client-side, correct? I cannot initially load the server-side ones and update them client-side when switching language client-side, correct?
at the end your translations (in this future version) are just JSON files. So you can (of course) load them on server as you just saw and if you want, you can also pass it down to all your cient components. I like to create a "DictionaryProvider" that provides the current dict to all my client component
Chinese AlligatorOP
Why is the use of t possible server side when using page routing, but not possible when using app routing?
@Chinese Alligator Why is the use of `t` possible server side when using page routing, but not possible when using app routing?
when using pages router everything is clientside by default and on the app router it's the other way around: everything is serverside by default. And hooks are not available on the serverside
@Chinese Alligator solved?