epic-stack icon indicating copy to clipboard operation
epic-stack copied to clipboard

Add i18n to epic stack

Open cjoecker opened this issue 5 months ago • 6 comments

I think internationalization is common nowadays, and most projects should start with it since implementing it in mature projects is costly.

In this discussion, it is said that i18n is planned, but it is still not implemented. There is this example project that can be migrated to this project.

cjoecker avatar Jul 01 '25 13:07 cjoecker

I'm open to looking at a PR for this, but I'm still not certain I'm ready to commit to anything here beyond an example.

kentcdodds avatar Jul 02 '25 03:07 kentcdodds

@kentcdodds what about having a do you want to include i18n question during the epic stack CLI setup?

cjoecker avatar Jul 03 '25 15:07 cjoecker

@kentcdodds I'm trying to add remix-i18next with the middleware to the Epic stack for the PR. As soon as I add the unstable_middleware=true flag to the react-router config without changing anything else, I get this error:

Unexpected Server Error

Error: Unable to create initial `unstable_RouterContextProvider` instance. Please confirm you are returning an instance of `Map<unstable_routerContext, unknown>` from your `getLoadContext` function.

Error: TypeError: init is not iterable

The error comes from the index.js file in the root of the project that gets called from the dev command. So anyone trying to use the epic stack with the middleware should be having the same issue. Any idea why?

@sergiodxa, maybe you know? The same is happening with the Vercel Plugin.

cjoecker avatar Jul 04 '25 14:07 cjoecker

Hi, the reason is that in middleware mode getLoadContext returns a unstable_InitialContext instead of AppLoadContext.

This: https://github.com/epicweb-dev/epic-stack/blob/4e6532d08219cef41299615ad7556b205aa0b77d/server/index.ts#L203 needs to be updated ala https://reactrouter.com/how-to/middleware#custom-server-with-getloadcontext

cha0s avatar Jul 14 '25 21:07 cha0s

Thanks @cha0s for the hint. I will give it a try!

cjoecker avatar Jul 22 '25 07:07 cjoecker

No problem!

Just be aware that anywhere using the context (e.g. app/routes/_seo+/sitemap[.]xml.ts) will need to be updated in tandem with this change, or will break!

cha0s avatar Jul 22 '25 19:07 cha0s