From 756f70cc548e44ed919c913816524649674ae0cf Mon Sep 17 00:00:00 2001 From: Igor Octaviano Date: Mon, 16 Dec 2019 11:41:41 -0300 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20Use=20env=20variable?= =?UTF-8?q?s=20to=20set=20locize=20(#1299)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of relying in dynamic configuration, use dedicated env variables to set locize api key / configuration Closes: #1271 --- .webpack/webpack.base.js | 5 +++++ platform/i18n/src/index.js | 17 +++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.webpack/webpack.base.js b/.webpack/webpack.base.js index 7d932bd26..d90236144 100644 --- a/.webpack/webpack.base.js +++ b/.webpack/webpack.base.js @@ -72,12 +72,17 @@ module.exports = (env, argv, { SRC_DIR, DIST_DIR }) => { }, plugins: [ new webpack.DefinePlugin({ + /* Application */ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV), 'process.env.DEBUG': JSON.stringify(process.env.DEBUG), 'process.env.APP_CONFIG': JSON.stringify(process.env.APP_CONFIG || ''), 'process.env.PUBLIC_URL': JSON.stringify(process.env.PUBLIC_URL || '/'), 'process.env.VERSION_NUMBER': JSON.stringify(PACKAGE.version || ''), 'process.env.BUILD_NUM': JSON.stringify(BUILD_NUM), + /* i18n */ + 'process.env.USE_LOCIZE': JSON.stringify(process.env.USE_LOCIZE || ''), + 'process.env.LOCIZE_PROJECTID': JSON.stringify(process.env.LOCIZE_PROJECTID || ''), + 'process.env.LOCIZE_API_KEY': JSON.stringify(process.env.LOCIZE_API_KEY || ''), }), ], // Fix: https://github.com/webpack-contrib/css-loader/issues/447#issuecomment-285598881 diff --git a/platform/i18n/src/index.js b/platform/i18n/src/index.js index f8b34fc9f..1ad95d090 100644 --- a/platform/i18n/src/index.js +++ b/platform/i18n/src/index.js @@ -29,19 +29,20 @@ function addLocales(newLocales) { customDebug(resourceBundle, 'info'); } -// Note: Developers can add the API key to use the in-context editor. -// DO NOT commit the API key -const config = (window.config && window.config.i18n) || {}; - +/* + * Note: Developers can add the API key to use the + * in-context editor using environment variables. + * (DO NOT commit the API key) + */ const locizeOptions = { - projectId: config.LOCIZE_PROJECTID, - apiKey: config.LOCIZE_API_KEY, + projectId: process.env.LOCIZE_PROJECTID, + apiKey: process.env.LOCIZE_API_KEY, referenceLng: 'en-US', fallbacklng: 'en-US', }; -const envUseLocize = !!config.USE_LOCIZE; -const envApiKeyAvailable = !!config.LOCIZE_API_KEY; +const envUseLocize = !!process.env.USE_LOCIZE; +const envApiKeyAvailable = !!process.env.LOCIZE_API_KEY; const DEFAULT_LANGUAGE = 'en-US'; function initI18n(