reactjsnext.jsfrontendbackend

Usetranslation, next.js SSR


I have a problem, I have an application and I use SSR, I change the language on the website and everything works fine when I don't go to the subpages that, let's say, reload and receive data from the server, e.g. /[id].tsx and tearz yes, the frontend still reads the path and I have e.g. en/job/jobid but with the server coming to it the translation is pl and there is no way in the world that the function is available after entering the subpage that I can read ten languages. Apparently lang is en

next-translate - compiled page: /job-board - locale: en - namespaces: common, job-board, search, offer, talent - used loader: getServerSideProps
next-translate - compiled page: /job-board - locale: en - namespaces: common, job-board, search, offer, talent - used loader: getServerSideProps
 ○ Compiling /offer/[slug] ...
 ✓ Compiled /offer/[slug] in 2.6s (1202 modules)
next-translate - compiled page: /offer/[slug] - locale: pl - namespaces: common, offer, talent, job-board, common - used loader: getServerSideProps

and I still have it in the path

http://localhost:3000/en/offer/oferid

well, Polish language comes from the server, how to do it or something


Solution

  • In the future if somebody will be have the same problem with language from SSR you can try with that

    export const getServerSideProps: GetServerSideProps = async (context) => {
    
        return context.req.url?.includes('/en/')
            ? { props: { locale: 'en' } }
            : { props: {} };
    
    };
    

    That will works for me, so i will leave that here.