Skip to content

Commit

Permalink
update deps for next example
Browse files Browse the repository at this point in the history
  • Loading branch information
adrai committed Nov 1, 2023
1 parent 75b8d22 commit 413f433
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
17 changes: 17 additions & 0 deletions example/next/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,23 @@ export default appWithTranslation(MyApp, nextI18nConfig);

Use the `ready` property from `useTranslation` to ensure the i18next instance is ready and that your translations are loaded to avoid the user seeing bare translation keys, below is a very simplistic example of this.

Also make sure you set the `partialBundledLanguages` option to true, like [here](https://github.com/i18next/i18next-http-backend/blob/master/example/next/next-i18next.config.js#L14).

```js
// ...
const isBrowser = typeof window !== 'undefined'

module.exports = {
backend: { /* ... */ },
i18n: {
defaultLocale: 'en',
locales: ['en', 'de'],
},
partialBundledLanguages: isBrowser && true,
// ...
}
```

ADVICE: I suggest you don't use this client-side only approach, but use the lazy-reload approach (below) instead!

```jsx
Expand Down
3 changes: 2 additions & 1 deletion example/next/next-i18next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ module.exports = {
debug: isDev,
backend: {
backendOptions: [{ expirationTime: isDev ? 0 : 60 * 60 * 1000 }, {}], // 1 hour
backends: isBrowser ? [LocalStorageBackend, HttpBackend]: [],
backends: isBrowser ? [LocalStorageBackend, HttpBackend] : [],
},
partialBundledLanguages: isBrowser && true,
// react: { // used only for the lazy reload
// bindI18n: 'languageChanged loaded',
// useSuspense: false
Expand Down
2 changes: 1 addition & 1 deletion example/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"i18next-http-backend": "2.3.1",
"i18next-localstorage-backend": "4.2.0",
"next": "14.0.1",
"next-i18next": "14.0.3"
"next-i18next": "15.0.0"
},
"devDependencies": {
"prop-types": "15.8.1"
Expand Down
2 changes: 1 addition & 1 deletion example/next/pages/client-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Header } from '../components/Header'
import { Footer } from '../components/Footer'

const ClientPage = () => {
const { t, ready } = useTranslation(['client-page', 'footer'])
const { t, ready, i18n } = useTranslation(['client-page', 'footer'])
if (!ready) return 'loading translations...'
// but because of this ready return, you may see a warning like this: "Expected server HTML to contain a matching text node for..."

Expand Down

0 comments on commit 413f433

Please sign in to comment.