next-translate icon indicating copy to clipboard operation
next-translate copied to clipboard

How to load all locales once

Open popuguytheparrot opened this issue 4 years ago • 4 comments

Hi guys.

I try new version with load namespace in gSP and have problem

When switching between pages, namespaces disappear. I want to load them once to avoid duplicating code in every page

popuguytheparrot avatar Nov 11 '20 09:11 popuguytheparrot

@popuguytheparrot The problem you mention is a limitation that now has Next.js when loading the SSG props, however, it is already caching when you navigate to the same page and therefore in this case does not download the namespaces again.

I have created an issue https://github.com/vercel/next.js/issues/19050 with an implementation proposal in Next.js, if this is carried out I suppose that then it will be easy to solve it.

aralroca avatar Nov 11 '20 11:11 aralroca

@aralroca no way to get the lang in _app gip?

popuguytheparrot avatar Nov 11 '20 12:11 popuguytheparrot

@aralroca no way to get the lang in _app gip?

Sure, you can just use the next-translate/appWithI18n in _app.js just for that, skiping the "build step". The only thing is that using a getInitialProps means that you are skiping also the page optimization. In other words, you don't have the pages prerendered at build time and you need to render them on request time, wasting CPU and time on each request

aralroca avatar Nov 11 '20 12:11 aralroca

avoid duplicating code in every page

@popuguytheparrot why you need to duplicate code in order to load the namespaces? This is done automatically by the "build step", and after 1.0.0 will be done even more transparent.

aralroca avatar Nov 20 '20 18:11 aralroca