-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
Vercel: Unable to load translations using getServerSideProps/loadTranslations #49
Comments
Hi @atanaskanchev, if the prebuilt I would start looking at the path's configuration after the
If none of these work, would you mind creating a repository where with the reproducible behaviour where I can try to find a solution? |
Hi @JCQuintas thanks for the quick response. I've recreated the issue here https://github.com/atanaskanchev/ni18n-nx-issue and it's deployed to https://ni18n-nx-issue-9y6puo3xe-atanaskanchev.vercel.app/dashboard In the config, if backend: isBrowser
? {
backends: [LocalStorageBackend, HttpBackend],
backendOptions: [
{ expirationTime: 24 * 60 * 60 * 1000 },
{ loadPath: `locales/${localePath}` },
],
}
: isRunningOnLocalhost
? { loadPath: `apps/ni18n-nx-issue/public/locales/${localePath}` }
: { loadPath: `locales/${localePath}` }, |
So it seems when deploying to vercel, we don't have access to the The current behaviour work if you are deploying using a A quick solution for your case right now would be to use |
Hi @JCQuintas I've had a try with |
Indeed, it didn't work. Looking at it deeper, it seems that the issue is on the https://github.com/vercel/nft packager that doesn't allow a "third party module" to flag a file as "necessary" out of its scope. So at the moment we can't really fix that automatically without creating a patch to the nft package and then waiting for vercel to update it. In the meantime, one workaround would be to create a function on your repository to do that for us // force-locales-packing.js
import path from 'path'
export const forceLocalesPacking = () => path.join('./public/locales') Then you should be able to run that inside your Let me know if it works for you, else I can update the repo you linked above with the steps necessary to make it work. |
This worked for me. import type { NamespacesNeeded, Ni18nOptions } from 'ni18n';
import { loadTranslations as ni18nLoadTranslations } from 'ni18n';
import path from 'path';
import { i18n } from '../../next.config';
export const namespaces = [
'common',
'register',
'dashboard',
'sidebar',
] as const;
export const ni18nConfig: Ni18nOptions = {
supportedLngs: i18n?.locales,
ns: namespaces,
};
export const loadTranslations = async (
initialLocale?: string | undefined,
namespacesNeeded?: NamespacesNeeded | undefined
) => {
const locales = path.resolve('./', './public/locales');
return await ni18nLoadTranslations(
ni18nConfig,
initialLocale,
namespacesNeeded
);
}; |
Has anyone found a solution to this? |
This solved my problem #49 (comment) const locales = path.resolve('./', './public/locales'); |
Hi @zaniluca, the main issue is on how the I haven't had the time to look at that more in depth and propose a solution, but in the meantime, the solution provided by @RodriguesCosta should work. |
Any solution on that? |
While the setup works fine running locally, the deployed to vercel app returns empty translations by loadTranslations in getServerSideProps
GET | https://app.vercel.app/_next/data/HZ7wajlS0AuNQGjuW_9so/en/app/dashboard.json
ni18n.config.ts
next.config.js
"i18next": "^21.6.5",
"i18next-chained-backend": "^3.0.2",
"i18next-http-backend": "^1.3.1",
"i18next-localstorage-backend": "^3.1.3",
"next": "12.0.7",
"ni18n": "^1.0.3-rc.0",
The text was updated successfully, but these errors were encountered: