Comments (10)
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
);
};
from ni18n.
Has anyone found a solution to this?
This solved my problem #49 (comment)
const locales = path.resolve('./', './public/locales');
from ni18n.
Hi @zaniluca, the main issue is on how the nft
package decides which file to bundle or not. A discussion regarding that can be found here: vercel/nft#77
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.
from ni18n.
Hi @atanaskanchev, if the prebuilt JSON
is empty it probably means the issue is on the build
step.
I would start looking at the path's configuration after the isRunningOnLocalhost
conditional.
It is possible you don't need the conditional at all, can you try one of the following solutions?
- use
undefined
- use
{ loadPath: `apps/ui-web-app/public/locales/${localePath}` }
- use
{ loadPath: `locales/${localePath}` }
If none of these work, would you mind creating a repository where with the reproducible behaviour where I can try to find a solution?
from ni18n.
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 !isRunningOnLocalhost
I am setting the locales path { loadPath: locales/${localePath}
} and it seems it matches the vercel workspace
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}` },
from ni18n.
So it seems when deploying to vercel, we don't have access to the public
folder from the getServerSideProps
. :(
The current behaviour work if you are deploying using a docker
container though... I've opened a bug issue on nextjs
repo and will keep you posted.
A quick solution for your case right now would be to use getStaticProps
instead for the time being, or use clientNamespaces
to have the translations loaded on the client only.
from ni18n.
Hi @JCQuintas I've had a try with v1.0.4-rc.3
but it seems the issue with Vercel still persist.
from ni18n.
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 getServerSideProps
and it will "tag" the files to be bundled. I intend on creating a documentation for this as well as soon as I have time. Then I try to work on a fix on the nft
package itself.
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.
from ni18n.
Has anyone found a solution to this?
from ni18n.
Any solution on that?
from ni18n.
Related Issues (20)
- Codesplitting not working without NextJS routing HOT 1
- Type declaration for appWithI18Next needs generic
- BUG? ni18n doesn't respect custom default namespace HOT 1
- Missing documentation about useSyncLanguage HOT 3
- Docs for testing setup?
- SSR broken in latest version of NextJS when setting locale manually HOT 10
- Abilty to fast reload translation files HOT 1
- Possible to manually set initial locale? HOT 2
- Translations flicker HOT 5
- release HOT 1
- Allow passing locale via page props HOT 3
- How to use multiple NS for one component HOT 3
- app-router supports HOT 7
- custom language selection not working SSR
- Environment variables in config? HOT 1
- ni18n with LanguageDetector
- I've Identified a Scenario Preventing ni18n from Functioning Properly
- loadTranslations does not load the default namespace correctly if not specified in config HOT 2
- ES5 Support? HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ni18n.