Skip to content

Commit

Permalink
try to fix namespacesRequired in serverSideTranslations is not type-s…
Browse files Browse the repository at this point in the history
…afe anymore #220
  • Loading branch information
adrai committed Sep 2, 2023
1 parent da1d3e4 commit d7b51bb
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 24 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 14.0.1

- try to fix namespacesRequired in serverSideTranslations is not type-safe anymore [#2201](https://github.com/i18next/next-i18next/issues/2201)

## 14.0.0

- requires i18next >= v23.0.1
Expand Down
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@
"eslint-plugin-typescript-sort-keys": "^2.1.0",
"gh-release": "7.0.2",
"husky": "^8.0.3",
"i18next": "^23.4.2",
"i18next": "^23.4.6",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"next": "^13.1.6",
"npm-run-all": "^4.1.5",
"prettier": "2.8.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-i18next": "^13.0.3",
"react-i18next": "^13.2.1",
"rimraf": "^4.1.2",
"size-limit": "^8.1.2",
"start-server-and-test": "^1.15.3",
Expand All @@ -137,9 +137,9 @@
"i18next-fs-backend": "^2.1.5"
},
"peerDependencies": {
"i18next": "^23.4.2",
"i18next": "^23.4.6",
"next": ">= 12.0.0",
"react": ">= 17.0.2",
"react-i18next": "^13.0.3"
"react-i18next": "^13.2.1"
}
}
9 changes: 5 additions & 4 deletions src/serverSideTranslations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { globalI18n } from './appWithTranslation'

import { UserConfig, SSRConfig } from './types'
import { getFallbackForLng, unique } from './utils'
import { Module } from 'i18next'
import { Module, Namespace } from 'i18next'

let DEFAULT_CONFIG_PATH = './next-i18next.config.js'

Expand All @@ -22,11 +22,12 @@ if (process.env.I18NEXT_DEFAULT_CONFIG_PATH) {
DEFAULT_CONFIG_PATH = process.env.I18NEXT_DEFAULT_CONFIG_PATH
}

type ArrayElementOrSelf<T> = T extends Array<infer U> ? U[] : T[]

export const serverSideTranslations = async (
initialLocale: string,
namespacesRequired:
| string
| string[]
| ArrayElementOrSelf<Namespace>
| undefined = undefined,
configOverride: UserConfig | null = null,
extraLocales: string[] | false = false
Expand Down Expand Up @@ -77,7 +78,7 @@ export const serverSideTranslations = async (
(b: Module) => b.type === 'backend'
)
if (hasCustomBackend && namespacesRequired) {
await i18n.loadNamespaces(namespacesRequired)
await i18n.loadNamespaces(Array.isArray(namespacesRequired) ? (namespacesRequired as string[]) : (namespacesRequired as string))
}

const initialI18nStore: Record<string, any> = {
Expand Down

0 comments on commit d7b51bb

Please sign in to comment.