-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add stripes translations mocking ability to tests
- Loading branch information
Wil Wilsman
committed
Sep 19, 2018
1 parent
b3404f7
commit c555329
Showing
3 changed files
with
40 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import componentTranslations from '@folio/stripes-components/translations/stripes-components/en'; | ||
import coreTranslations from '../../../translations/stripes-core/en'; | ||
|
||
const { keys, assign } = Object; | ||
|
||
function prefixKeys(pre, obj) { | ||
return keys(obj).reduce((memo, key) => { | ||
return assign(memo, { [`${pre}.${key}`]: obj[key] }); | ||
}, {}); | ||
} | ||
|
||
const defaultTranslations = { | ||
en: { | ||
...prefixKeys('stripes-core', coreTranslations), | ||
...prefixKeys('stripes-components', componentTranslations) | ||
} | ||
}; | ||
|
||
export default function withTranslations(server, translations = {}) { | ||
// eslint-disable-next-line | ||
server.pretender.get(`${__webpack_public_path__}translations/:file`, req => { | ||
const [lang] = req.params.file.split('-'); | ||
|
||
return [200, {}, JSON.stringify({ | ||
...defaultTranslations[lang] || {}, | ||
...translations[lang] || {} | ||
})]; | ||
}); | ||
} |
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