-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve i18next integration (#3146)
- Loading branch information
Showing
24 changed files
with
116 additions
and
71 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { TolgeePlugin } from '@tolgee/web'; | ||
|
||
export const I18nextPlugin = (): TolgeePlugin => (tolgee) => { | ||
tolgee.updateOptions({ ns: [] }); | ||
tolgee.updateOptions({ ns: [], defaultNs: undefined }); | ||
return tolgee; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
jest.autoMockOff(); | ||
|
||
import '@testing-library/jest-dom'; | ||
import { mockCoreFetch } from '@tolgee/testing/fetchMock'; | ||
import i18n from 'i18next'; | ||
import { DevTools, Tolgee } from '@tolgee/web'; | ||
import { withTolgee, I18nextPlugin } from '..'; | ||
|
||
const API_URL = 'http://localhost'; | ||
const API_KEY = 'dummyApiKey'; | ||
|
||
const fetch = mockCoreFetch(); | ||
|
||
describe('withTolgee', () => { | ||
let i18next: typeof i18n; | ||
beforeEach(async () => { | ||
fetch.enableMocks(); | ||
}); | ||
|
||
afterEach(() => { | ||
i18next?.tolgee?.stop(); | ||
}); | ||
|
||
it('loads static data first', async () => { | ||
const tolgee = Tolgee() | ||
.use(DevTools()) | ||
.use(I18nextPlugin()) | ||
.init({ | ||
staticData: { | ||
'en:translation': { | ||
hello_world: 'Hello static!', | ||
}, | ||
}, | ||
}); | ||
|
||
i18next = withTolgee(i18n.createInstance(), tolgee); | ||
await i18next.init({ lng: 'en', supportedLngs: ['en'] }); | ||
expect(i18next.t('hello_world')).toContain('Hello static!'); | ||
}); | ||
|
||
it('loads dev data over static data', async () => { | ||
const tolgee = Tolgee() | ||
.use(DevTools()) | ||
.use(I18nextPlugin()) | ||
.init({ | ||
apiUrl: API_URL, | ||
apiKey: API_KEY, | ||
staticData: { | ||
'en:translation': { | ||
hello_world: 'Hello static!', | ||
}, | ||
}, | ||
}); | ||
|
||
i18next = withTolgee(i18n.createInstance(), tolgee); | ||
await i18next.init({ lng: 'en', supportedLngs: ['en'] }); | ||
expect(i18next.t('hello_world')).toContain('Hello world!'); | ||
}); | ||
|
||
it('loads dev data on lang change', async () => { | ||
const tolgee = Tolgee() | ||
.use(DevTools()) | ||
.use(I18nextPlugin()) | ||
.init({ | ||
apiUrl: API_URL, | ||
apiKey: API_KEY, | ||
staticData: { | ||
'en:translation': { | ||
hello_world: 'Hello static!', | ||
}, | ||
}, | ||
}); | ||
|
||
i18next = withTolgee(i18n.createInstance(), tolgee); | ||
await i18next.init({ lng: 'en', supportedLngs: ['en', 'cs'] }); | ||
expect(i18next.t('hello_world')).toContain('Hello world!'); | ||
await i18next.changeLanguage('cs'); | ||
expect(i18next.t('hello_world')).toContain('Ahoj světe!'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters