Getting empty server side translations on build
See original GitHub issueDescribe 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:
- Created a year ago
- Comments:5 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
Oh yeah, server and client have different need for sure, however when working with next we actually have 3 “sides”:
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
fromserverSideTranslations
: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. IMOserverSideTranslations
should use the node one whileappWithTranslations
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 thenode
andbrowser
version ofcreateClient
, 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.