question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting empty server side translations on build

See original GitHub issue

Describe the bug

Next does page building asynchronously, and on occasion certain serverSideTranslations calls return empty even though the translation files exist.

Seems to happen when using a separate backend for the client-side.

Occurs in next-i18next version

next-i18next: 11.0.0

Steps to reproduce

Example repo Run npm run build and check console for logs of empty translations.

Expected behaviour

Translations should be loaded correctly.

Additional context

I’m pretty sure the use of the globalInstance on the createClient is what is causing the error, as I comment that out to always create a new client it works as intended.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
joaomankecommented, Jul 6, 2022

Regarding issue 1897, I’m down to contribute with a PR. I’m currently stuffed at work, but I can try to get something going later this week or next week.

0reactions
joaomankecommented, Jul 6, 2022

Oh yeah, server and client have different need for sure, however when working with next we actually have 3 “sides”:

  • server: apis, data fetching methods (getServerSideProps and others)
  • client:
    • server version (SSR or build time SSG)
    • browser version (hydrated version on the user’s side)

While the server and client parts do have different needs (ie. HttpBackend vs FileSystemBackend), the server and browser version of the client should match as best as possible, React 18 actually throws an error now when they don’t (html wise).

In my view what could (or should) be done:

Decouple appWithTranslations from serverSideTranslations:

These are executed in different stages and are used in distinct enough ways that they should be isolated from one another. The point where they meet is in the createClient function, which has a browser and a node version. IMO serverSideTranslations should use the node one while appWithTranslations should use the browser one always.

“Bring your own global”:

The node version createClient, using globals internally is a bit dangerous, as you don’t really know when the code will be executed exacly (is it on build? on the server? a mix?), if instead you allow (or force) the user to instanciate their own “global” instance they can instanciate it before everything starts going, and we don’t have to worry about instanciating on the go, unless nothing has been provided, in which case we always instanciate a new one for each call.

With this the user could configure and share with other libraries that can share a i18n instance as well, plus this is the only difference between the node and browser version of createClient, therefore in this case we could reuse the exact same function passing a “global” as needed.

Let me also say that I am no expert, so these are just things tha I would prefer/do, I am not familiar with every i18n use case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting empty server side translations on build #1890 - GitHub
Run npm run build and check console for logs of empty translations. Expected behaviour. Translations should be loaded correctly. Additional ...
Read more >
Add or Load Translations - i18next documentation
There are a few options to load translations to your application instrumented by ... Please make sure to at least pass in an...
Read more >
How to access locale in custom app on server-side in Next.js?
You can access the locale in your custom app's getInitialProps through the router prop. static async getInitialProps({ Component, ctx, ...
Read more >
Implementing multi-language Angular applications rendered ...
This article will teach you what you need to know to successfully implement multi-language Angular applications rendered server-side.
Read more >
Continuous localization — Weblate 4.15.1 documentation
Weblate pulls changes from the VCS repository, see Updating repositories. Once Weblate detects changes in translations, translators are notified based on their ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found