Skip to content

Commit

Permalink
update i18next deps
Browse files Browse the repository at this point in the history
  • Loading branch information
adrai committed Aug 6, 2023
1 parent 4679153 commit d4aea29
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 48 deletions.
34 changes: 17 additions & 17 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.2.3",
"i18next": "^23.4.2",
"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.1",
"react-i18next": "^13.0.3",
"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.2.3",
"i18next": "^23.4.2",
"next": ">= 12.0.0",
"react": ">= 17.0.2",
"react-i18next": "^13.0.1"
"react-i18next": "^13.0.3"
}
}
18 changes: 9 additions & 9 deletions src/config/createConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ describe('createConfig', () => {
.mockReturnValueOnce(true)

const config = createConfig({
fallbackLng: code => code.split('-')[0],
fallbackLng: (code: string) => code.split('-')[0],
i18n: {
defaultLocale: 'de',
locales: ['de', 'en', 'en-US'],
Expand Down Expand Up @@ -356,10 +356,10 @@ describe('createConfig', () => {

describe('with a function for localePath', () => {
const localePathFn: UserConfig['localePath'] = (
locale,
namespace,
missing
) => `${missing}/${namespace}/${locale}.json`
locale: string,
namespace: string,
missing: boolean
) => `${missing ? 'true' : 'false'}/${namespace}/${locale}.json`

it('returns a config whose localePath works as expected', () => {
;(fs.existsSync as jest.Mock).mockReturnValueOnce(true)
Expand Down Expand Up @@ -594,10 +594,10 @@ describe('createConfig', () => {

describe('with a function for localePath', () => {
const localePathFn: UserConfig['localePath'] = (
locale,
namespace,
missing
) => `${missing}/${namespace}/${locale}.json`
locale: string,
namespace: string,
missing: boolean
) => `${missing ? 'true' : 'false'}/${namespace}/${locale}.json`

it('returns a config whose localePath works as expected', () => {
const config = createConfig({
Expand Down
12 changes: 6 additions & 6 deletions src/config/createConfig.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defaultConfig } from './defaultConfig'
import { InternalConfig, UserConfig } from '../types'
import { getFallbackForLng, unique } from '../utils'
import { FallbackLngObjList } from 'i18next'
import { FallbackLngObjList, Module } from 'i18next'

const deepMergeObjects = ['backend', 'detection'] as (keyof Pick<
UserConfig,
Expand Down Expand Up @@ -36,7 +36,7 @@ export const createConfig = (
nonExplicitSupportedLngs,
} = combinedConfig

const locales = combinedConfig.locales.filter(l => l !== 'default')
const locales = combinedConfig.locales.filter((l: string) => l !== 'default')

/**
* Skips translation file resolution while in cimode
Expand Down Expand Up @@ -77,16 +77,16 @@ export const createConfig = (

if (typeof fallbackLng === 'string') {
combinedConfig.fallbackLng = combinedConfig.locales
.filter(l => l.includes('-'))
.filter((l: string) => l.includes('-'))
.reduce(createFallbackObject, { default: [fallbackLng] })
} else if (Array.isArray(fallbackLng)) {
combinedConfig.fallbackLng = combinedConfig.locales
.filter(l => l.includes('-'))
.filter((l: string) => l.includes('-'))
.reduce(createFallbackObject, { default: fallbackLng })
} else if (typeof fallbackLng === 'object') {
combinedConfig.fallbackLng = Object.entries(
combinedConfig.fallbackLng
).reduce<FallbackLngObjList>((acc, [l, f]) => {
).reduce<FallbackLngObjList>((acc, [l, f]: [string, any]) => {
acc[l] = l.includes('-')
? unique([l.split('-')[0], ...f])
: f
Expand All @@ -100,7 +100,7 @@ export const createConfig = (
}

const hasCustomBackend = userConfig?.use?.some(
b => b.type === 'backend'
(b: Module) => b.type === 'backend'
)
if (!process.browser && typeof window === 'undefined') {
combinedConfig.preload = locales
Expand Down
4 changes: 2 additions & 2 deletions src/createClient/browser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import i18n from 'i18next'
import i18n, { Module } from 'i18next'

import {
InternalConfig,
Expand All @@ -12,7 +12,7 @@ export default (config: InternalConfig): CreateClientReturn => {
let initPromise: InitPromise

if (!instance.isInitialized) {
config?.use?.forEach(x => instance.use(x))
config?.use?.forEach((x: Module) => instance.use(x))
if (typeof config.onPreInitI18next === 'function') {
config.onPreInitI18next(instance)
}
Expand Down
8 changes: 5 additions & 3 deletions src/createClient/node.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import i18n from 'i18next'
import i18n, { Module } from 'i18next'
import i18nextFSBackend from 'i18next-fs-backend'

import {
Expand All @@ -19,20 +19,22 @@ export default (config: InternalConfig): CreateClientReturn => {
} else {
instance = globalInstance.cloneInstance({
...config,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
initImmediate: false,
})
}
let initPromise: InitPromise

if (!instance.isInitialized) {
const hasCustomBackend = config?.use?.some(
b => b.type === 'backend'
(b: Module) => b.type === 'backend'
)
if (!hasCustomBackend) {
instance.use(i18nextFSBackend)
}

config?.use?.forEach(x => instance.use(x))
config?.use?.forEach((x: Module) => instance.use(x))
if (typeof config.onPreInitI18next === 'function') {
config.onPreInitI18next(instance)
}
Expand Down
12 changes: 6 additions & 6 deletions src/serverSideTranslations.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ describe('serverSideTranslations', () => {
'en-US',
['common'],
{
fallbackLng: code => code.split('-')[0],
fallbackLng: (code: string) => code.split('-')[0],
i18n: {
defaultLocale: 'de',
locales: ['de', 'en-US'],
Expand Down Expand Up @@ -504,7 +504,7 @@ describe('serverSideTranslations', () => {

it('does thrown an error with fallbackLng (as function)', async () => {
const config: UserConfig = {
fallbackLng: code => (code === 'de-AT' ? 'de' : 'en'),
fallbackLng: (code: string) => (code === 'de-AT' ? 'de' : 'en'),
i18n: {
defaultLocale: 'de',
locales: ['de', 'en-US', 'de-DE'],
Expand Down Expand Up @@ -583,10 +583,10 @@ describe('serverSideTranslations', () => {

it('throws if a function is used for localePath and namespaces are not provided', async () => {
const localePathFn: UserConfig['localePath'] = (
locale,
namespace,
missing
) => `${missing}/${namespace}/${locale}.json`
locale: string,
namespace: string,
missing: boolean
) => `${missing ? 'true' : 'false'}/${namespace}/${locale}.json`
const config: UserConfig = {
i18n: {
defaultLocale: 'en',
Expand Down
3 changes: 2 additions & 1 deletion src/serverSideTranslations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { globalI18n } from './appWithTranslation'

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

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

Expand Down Expand Up @@ -73,7 +74,7 @@ export const serverSideTranslations = async (
await initPromise

const hasCustomBackend = userConfig?.use?.some(
b => b.type === 'backend'
(b: Module) => b.type === 'backend'
)
if (hasCustomBackend && namespacesRequired) {
await i18n.loadNamespaces(namespacesRequired)
Expand Down

0 comments on commit d4aea29

Please sign in to comment.