From 66fc1dd73921ad020dfc9e8386e75e8557f01a29 Mon Sep 17 00:00:00 2001 From: Rodrigo Antinarelli Date: Thu, 13 Jun 2019 14:22:10 -0300 Subject: [PATCH] fix require.context bug --- extensions/ohif-i18n/src/index.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/extensions/ohif-i18n/src/index.js b/extensions/ohif-i18n/src/index.js index 8214b013f..f11da3c37 100755 --- a/extensions/ohif-i18n/src/index.js +++ b/extensions/ohif-i18n/src/index.js @@ -31,6 +31,12 @@ function getKeyForNameSpaces(key) { } function getLocales() { + const isWebpackEnv = typeof require.context === 'function'; + // require.context is exclusive from webpack, it's needed to escape inside jest + if (!isWebpackEnv) { + return {}; + } + const context = require.context(`./locales`, true, /\.json$/); const locales = {}; @@ -85,10 +91,6 @@ customDebug(`version ${pkg.version} loaded.`, 'info'); initI18n(); -export { - translate as t, - addLocales, - initI18n -}; +export { translate as t, addLocales, initI18n }; export default i18n;