Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use the central i18n mocks for all tests and add support for variables
- Loading branch information
Showing
187 changed files
with
392 additions
and
1,863 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* eslint-env node */ | ||
import { TFunction } from 'i18next'; | ||
|
||
const i18next = require.requireActual('i18next'); | ||
|
||
const interpolationPattern = /{{([A-Za-z0-9]+)}}/; | ||
|
||
export const t = ((key: string, interpolation: Record<string, string>) => { | ||
let result = key.includes('~') ? key.substring(key.indexOf('~') + 1) : key; | ||
while (interpolation && result.match(interpolationPattern)) { | ||
result = result.replace(interpolationPattern, (_, variable) => interpolation[variable] || ''); | ||
} | ||
return result; | ||
}) as TFunction; | ||
|
||
module.exports = { | ||
...i18next, | ||
t, | ||
default: { | ||
...i18next.default, | ||
use() { | ||
return this; | ||
}, | ||
init: () => Promise.resolve(), | ||
t, | ||
}, | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* eslint-env node */ | ||
const i18next = require('i18next'); | ||
const react = require.requireActual('react'); | ||
const reactI18next = require.requireActual('react-i18next'); | ||
|
||
module.exports = { | ||
...reactI18next, | ||
useTranslation: () => ({ t: i18next.t }), | ||
withTranslation: () => (component) => (props) => | ||
react.createElement(component, { ...props, t: i18next.t }), | ||
}; |
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
Oops, something went wrong.