Skip to content

Commit

Permalink
fix: Respect configOverride.resources (#1707)
Browse files Browse the repository at this point in the history
* fix: resources of configOverride doesn't work

* fix: Respect configOverride.resources

Co-authored-by: Md. Rubayet Hossain <[email protected]>
  • Loading branch information
isaachinman and rubayethossain authored Feb 23, 2022
1 parent 8999125 commit 8d13429
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/appWithTranslation.client.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,34 @@ describe('appWithTranslation', () => {
expect(args[0].i18n.options.configOverride).toBe('custom-value')
})

it('allows passing configOverride.resources', () => {
const DummyAppConfigOverride = appWithTranslation(() => (
<div>Hello world</div>
), {
i18n: {
defaultLocale: 'en',
locales: ['en', 'de'],
},
resources: {
xyz: {
custom: 'resources',
},
},
} as any)
render(
<DummyAppConfigOverride
{...createProps()}
/>
)
const [args] = (I18nextProvider as jest.Mock).mock.calls

expect(args[0].i18n.options.resources).toMatchObject({
xyz: {
custom: 'resources',
},
})
})

it('throws an error if userConfig and configOverride are both missing', () => {
const DummyAppConfigOverride = appWithTranslation(() => (
<div>Hello world</div>
Expand Down
4 changes: 3 additions & 1 deletion src/appWithTranslation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export const appWithTranslation = <Props extends AppProps = AppProps>(

let { userConfig } = _nextI18Next
const { initialI18nStore } = _nextI18Next
const resources =
configOverride?.resources ? configOverride.resources : initialI18nStore

if (userConfig === null && configOverride === null) {
throw new Error('appWithTranslation was called without a next-i18next config')
Expand All @@ -52,7 +54,7 @@ export const appWithTranslation = <Props extends AppProps = AppProps>(
lng: locale,
}),
lng: locale,
resources: initialI18nStore,
resources,
}).i18n

globalI18n = instance
Expand Down

0 comments on commit 8d13429

Please sign in to comment.