Comments (7)
@aralroca I found the same issue recently when I started to migrate pages from pages
to app
. The first page I migrated was a static page so I simply used a export const dynamic = "force-static";
to deal with it.
Right now I started to migrate pages with translations and this is definitely a bigger issue given that any page I migrate will be dynamic because of next-translate. Are we missing something with the next-translate configuration?
Edit: I found the culprit, I tried to remove props.searchParams?.lang
by hand and the problem was gone.
The usage of searchParams will make all the pages dynamic,
searchParams is a Dynamic API whose values cannot be known ahead of time. Using it will opt the page into dynamic rendering at request time.
I don't know what would be the alternative given that I'm not deep into the possible ramifications.
from next-translate.
@jakubjanousek @aralroca this is not a (final) solution but it displays where the problem is with the given repo,
hensansi/next-translate-ssg-issue@f1d1aad
Creating an optimized production build .Route (app) Size First Load JS
┌ ○ / 5.35 kB 85.8 kB
└ ○ /_not-found 884 B 81.3 kB
+ First Load JS shared by all 80.4 kB
├ chunks/738-70faf364855414b4.js 27.5 kB
├ chunks/fd9d1056-9c5946da9b5f2b9d.js 51 kB
├ chunks/main-app-ab8e99cf22ecae19.js 230 B
└ chunks/webpack-396734a053f7bdbb.js 1.75 kB
from next-translate.
good catch @hensansi, unfortunately I am not familiar with the reasons why searchParams is there
for now, we have removed next-translate-plugin
and created custom useTranslation
that just directly calls transCore with statically imported translation file
this allows us to have SSG by default while keeping all of the next-translate interface, but it is a very specific use case, since each of our languages is a single site that knows its locale at build time
from next-translate.
I'm having the same problem
@jakubjanousek Can I share your useTranslation
implementation code?
from next-translate.
for now, we have removed next-translate-plugin and created custom useTranslation that just directly calls transCore with statically imported translation file
@jakubjanousek Could you please share the code snippet or implementation details for this? It would be greatly helpful to understand how you integrated this into your setup.
from next-translate.
Our situation is a bit specific that we have several deployment, but each has only a single translation. Therefore we are able to copy only the necessary translation before starting the server into current
a simplified version is something like this
import transCore from 'next-translate/transCore'
import currentLocale from 'locales/current/main.json'
import { Translate } from 'next-translate'
const lang = process.env.LOCALE || 'en'
const tWithoutNs = transCore({
lang,
config: {
locales: [locale],
defaultLocale: locale,
defaultNS: 'main',
loader: false,
pages: {
'*': ['main'],
},
},
pluralRules: new Intl.PluralRules(lang),
allNamespaces: { main: currentLocale as any },
})
export const getTranslate = () =>
({
t: (key: string, query?: any, options = {}) => {
return tWithoutNs(key, query, { ns: 'main', ...options })
},
} as { t: Translate })
from next-translate.
Our situation is a bit specific that we have several deployment, but each has only a single translation. Therefore we are able to copy only the necessary translation before starting the server into current
a simplified version is something like this
import transCore from 'next-translate/transCore' import currentLocale from 'locales/current/main.json' import { Translate } from 'next-translate' const lang = process.env.LOCALE || 'en' const tWithoutNs = transCore({ lang, config: { locales: [locale], defaultLocale: locale, defaultNS: 'main', loader: false, pages: { '*': ['main'], }, }, pluralRules: new Intl.PluralRules(lang), allNamespaces: { main: currentLocale as any }, }) export const getTranslate = () => ({ t: (key: string, query?: any, options = {}) => { return tWithoutNs(key, query, { ns: 'main', ...options }) }, } as { t: Translate })
@jakubjanousek Thank you so much for sharing your code and approach. In the end, we switched to using next-intl which solved our problems.
from next-translate.
Related Issues (20)
- TypeError: Cannot read properties of undefined (reading 'loadLocaleFrom') HOT 1
- Locale slug is added to api and other routes outside of app dir
- AppDirI18nProvider is not loaded after refresh, so lang is null HOT 2
- Change language without modifying the URL (/[lang]/rest) HOT 4
- add Dependabot HOT 1
- Next.js app build fails due to empty lang value HOT 3
- change "Twitter" shields badge to "𝕏 " in README.md
- 404 error pages with next 14 HOT 20
- Localizations not working in prod bundle on NextJs 14 HOT 1
- Buildng project using only app router HOT 9
- Translation not working on client component inside layout HOT 10
- Warning: Detected multiple renderers concurrently rendering the same context provider.
- 404 when accssing homepage HOT 7
- 404 on root when using baseURL in vercel HOT 1
- Can't resolve 'next-translate/appWithI18n' on 2.7.0-canary.1 HOT 6
- Cold Start on dynamic routes HOT 5
- Type safety for getT function
- Regular locale naming like "en" breaks the i18n config HOT 1
- Cannot read properties of undefined (reading 'localesToIgnore')
- Docs reference incorrect format/formatter options HOT 1
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 next-translate.