Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reloadOnPrerender option to reload resources in serverSideTranslations so that developers don't have to restart their server when making changes to their translation JSON files #1359

Merged
merged 6 commits into from
Sep 1, 2021

Conversation

dcporter44
Copy link
Contributor

I talked with @isaachinman at the bottom of this thread (issue #881) regarding a solution to call i18n.reloadResources() inside of serverSideTranslations. Looks like there are several issues that have been created about this topic.

I've created a new config option called reloadOnPrerender that reloads the resources in severSideTranslations. I've updated the README as well.

@vercel
Copy link

vercel bot commented Aug 16, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/isaachinman/next-i18next/BEzd7D7c8D1QEQiNm44sFeKpZPfK
✅ Preview: https://next-i18next-git-fork-dcporter44-master-isaachinman.vercel.app

Copy link
Contributor

@isaachinman isaachinman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm somewhat surprised that calling reloadResources on globalI18n works, but if so, this is quite an easy win.

We will need test coverage, though. Thanks!

src/serverSideTranslations.ts Show resolved Hide resolved
@tigressbailey

This comment has been minimized.

@dcporter44
Copy link
Contributor Author

dcporter44 commented Aug 22, 2021

@isaachinman Let me know if this test implementation seems correct. In order to test if reloadResources is called, I need to have access to the globalI18n object created by appWithTranslation. In order to do that I had to create a dummy component (like you did in appWithTranslation.test.tsx) so that globalI18n would be instantiated.

Copy link
Contributor

@isaachinman isaachinman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test coverage looks fine. Just had a passing thought about the API signature to avoid unintended regressions in prod envs.

README.md Show resolved Hide resolved
@janklimo
Copy link

If my understanding is correct, this will not enable HMR of locale files. If that's the case, I think we shouldn't have dismissed #1370 as it provides better DX.

@isaachinman
Copy link
Contributor

@janklimo As I've stated numerous times, next-i18next will not support HMR, as users can easily set this up themselves via their i18next config.

This PR, however, is a one-liner and is easy to maintain.

@janklimo
Copy link

@isaachinman I see, thank you for your response. I'm just getting started with the package so I'm not aware of the previous conversations. Would you have any pointers to a resource which explains how it can be easily done using i18next config? Perhaps we could add a readme section explaining it?

@MartinCura
Copy link

MartinCura commented Sep 4, 2021

Hi! Is this complete functionality? Would reeeally make DX better on the app i'm working at the moment. Is it gonna be included in a release soon?

@isaachinman
Copy link
Contributor

The reloadOnPrerender option has been released in [email protected].

@MartinCura
Copy link

Thank you for the release! Saving the .json doesn't load the new strings after turning on the option but i suppose it's because modifying components and saving those files doesn't make getServerSideProps get called in my setup?

@reymons
Copy link

reymons commented Nov 1, 2021

Thank you for the release! Saving the .json doesn't load the new strings after turning on the option but i suppose it's because modifying components and saving those files doesn't make getServerSideProps get called in my setup?

Yes. If it's gssp, you have to reload the page

@sunknudsen
Copy link

Is there a way to live update app when changes are made to translation files in locales directory?

@CommanderRedYT
Copy link

Is there a way to live update app when changes are made to translation files in locales directory?

It only works for me if the translations are JavaScript files that are exporting the translation object and using that in i18n.resources

@sunknudsen
Copy link

sunknudsen commented Mar 29, 2023

@CommanderRedYT Thanks for helping out!

Adding following to next-i18next.config.mjs worked for me.

import en from "./locales/en/common.json" assert { type: "json" }
import fr from "./locales/fr/common.json" assert { type: "json" }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants