From 5f8db72a741d661a76304f5543b658baae7c339a Mon Sep 17 00:00:00 2001 From: drafish Date: Wed, 20 Dec 2023 08:55:26 +0800 Subject: [PATCH] read and combine locale json files --- .../src/app/tabs/locales/en/index.js | 46 +++++------------ .../src/app/tabs/locales/es/index.js | 47 ++++++------------ .../src/app/tabs/locales/fr/index.js | 47 ++++++------------ .../src/app/tabs/locales/it/index.js | 47 ++++++------------ .../src/app/tabs/locales/zh/index.js | 49 ++++++------------- 5 files changed, 67 insertions(+), 169 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/locales/en/index.js b/apps/remix-ide/src/app/tabs/locales/en/index.js index 8da7dd179f..b3074531b9 100644 --- a/apps/remix-ide/src/app/tabs/locales/en/index.js +++ b/apps/remix-ide/src/app/tabs/locales/en/index.js @@ -1,37 +1,13 @@ -import debuggerJson from './debugger.json'; -import filePanelJson from './filePanel.json'; -import homeJson from './home.json'; -import panelJson from './panel.json'; -import pluginManagerJson from './pluginManager.json'; -import searchJson from './search.json'; -import settingsJson from './settings.json'; -import solidityJson from './solidity.json'; -import terminalJson from './terminal.json'; -import udappJson from './udapp.json'; -import solidityUnitTestingJson from './solidityUnitTesting.json'; -import permissionHandlerJson from './permissionHandler.json'; -import electronJson from './electron.json'; -import solUmlGenJson from './solUmlGen.json' -import remixAppJson from './remixApp.json' -import remixUiTabsJson from './remixUiTabs.json' -import circuitJson from './circuit.json'; +function readAndCombineJsonFiles() { + const dataContext = require.context('./', true, /\.json$/) -export default { - ...debuggerJson, - ...filePanelJson, - ...homeJson, - ...panelJson, - ...pluginManagerJson, - ...searchJson, - ...settingsJson, - ...solidityJson, - ...terminalJson, - ...udappJson, - ...solidityUnitTestingJson, - ...permissionHandlerJson, - ...electronJson, - ...solUmlGenJson, - ...remixAppJson, - ...remixUiTabsJson, - ...circuitJson + let combinedData = {} + dataContext.keys().forEach((key) => { + const jsonData = dataContext(key) + combinedData = {...combinedData, ...jsonData} + }) + + return combinedData } + +export default readAndCombineJsonFiles() diff --git a/apps/remix-ide/src/app/tabs/locales/es/index.js b/apps/remix-ide/src/app/tabs/locales/es/index.js index ded9c45b14..d1dbf937cd 100644 --- a/apps/remix-ide/src/app/tabs/locales/es/index.js +++ b/apps/remix-ide/src/app/tabs/locales/es/index.js @@ -1,36 +1,17 @@ -import debuggerJson from './debugger.json'; -import filePanelJson from './filePanel.json'; -import homeJson from './home.json'; -import panelJson from './panel.json'; -import pluginManagerJson from './pluginManager.json'; -import searchJson from './search.json'; -import settingsJson from './settings.json'; -import solidityJson from './solidity.json'; -import terminalJson from './terminal.json'; -import udappJson from './udapp.json'; -import solidityUnitTestingJson from './solidityUnitTesting.json'; -import permissionHandlerJson from './permissionHandler.json'; -import solUmlGenJson from './solUmlGen.json' -import remixAppJson from './remixApp.json' -import remixUiTabsJson from './remixUiTabs.json' -import enJson from '../en'; +import enJson from '../en' + +function readAndCombineJsonFiles() { + const dataContext = require.context('./', true, /\.json$/) + + let combinedData = {} + dataContext.keys().forEach((key) => { + const jsonData = dataContext(key) + combinedData = {...combinedData, ...jsonData} + }) + + return combinedData +} // There may have some un-translated content. Always fill in the gaps with EN JSON. // No need for a defaultMessage prop when render a FormattedMessage component. -export default Object.assign({}, enJson, { - ...debuggerJson, - ...filePanelJson, - ...homeJson, - ...panelJson, - ...pluginManagerJson, - ...searchJson, - ...settingsJson, - ...solidityJson, - ...terminalJson, - ...udappJson, - ...solidityUnitTestingJson, - ...permissionHandlerJson, - ...solUmlGenJson, - ...remixAppJson, - ...remixUiTabsJson, -}) +export default Object.assign({}, enJson, readAndCombineJsonFiles()) diff --git a/apps/remix-ide/src/app/tabs/locales/fr/index.js b/apps/remix-ide/src/app/tabs/locales/fr/index.js index ded9c45b14..d1dbf937cd 100644 --- a/apps/remix-ide/src/app/tabs/locales/fr/index.js +++ b/apps/remix-ide/src/app/tabs/locales/fr/index.js @@ -1,36 +1,17 @@ -import debuggerJson from './debugger.json'; -import filePanelJson from './filePanel.json'; -import homeJson from './home.json'; -import panelJson from './panel.json'; -import pluginManagerJson from './pluginManager.json'; -import searchJson from './search.json'; -import settingsJson from './settings.json'; -import solidityJson from './solidity.json'; -import terminalJson from './terminal.json'; -import udappJson from './udapp.json'; -import solidityUnitTestingJson from './solidityUnitTesting.json'; -import permissionHandlerJson from './permissionHandler.json'; -import solUmlGenJson from './solUmlGen.json' -import remixAppJson from './remixApp.json' -import remixUiTabsJson from './remixUiTabs.json' -import enJson from '../en'; +import enJson from '../en' + +function readAndCombineJsonFiles() { + const dataContext = require.context('./', true, /\.json$/) + + let combinedData = {} + dataContext.keys().forEach((key) => { + const jsonData = dataContext(key) + combinedData = {...combinedData, ...jsonData} + }) + + return combinedData +} // There may have some un-translated content. Always fill in the gaps with EN JSON. // No need for a defaultMessage prop when render a FormattedMessage component. -export default Object.assign({}, enJson, { - ...debuggerJson, - ...filePanelJson, - ...homeJson, - ...panelJson, - ...pluginManagerJson, - ...searchJson, - ...settingsJson, - ...solidityJson, - ...terminalJson, - ...udappJson, - ...solidityUnitTestingJson, - ...permissionHandlerJson, - ...solUmlGenJson, - ...remixAppJson, - ...remixUiTabsJson, -}) +export default Object.assign({}, enJson, readAndCombineJsonFiles()) diff --git a/apps/remix-ide/src/app/tabs/locales/it/index.js b/apps/remix-ide/src/app/tabs/locales/it/index.js index ded9c45b14..d1dbf937cd 100644 --- a/apps/remix-ide/src/app/tabs/locales/it/index.js +++ b/apps/remix-ide/src/app/tabs/locales/it/index.js @@ -1,36 +1,17 @@ -import debuggerJson from './debugger.json'; -import filePanelJson from './filePanel.json'; -import homeJson from './home.json'; -import panelJson from './panel.json'; -import pluginManagerJson from './pluginManager.json'; -import searchJson from './search.json'; -import settingsJson from './settings.json'; -import solidityJson from './solidity.json'; -import terminalJson from './terminal.json'; -import udappJson from './udapp.json'; -import solidityUnitTestingJson from './solidityUnitTesting.json'; -import permissionHandlerJson from './permissionHandler.json'; -import solUmlGenJson from './solUmlGen.json' -import remixAppJson from './remixApp.json' -import remixUiTabsJson from './remixUiTabs.json' -import enJson from '../en'; +import enJson from '../en' + +function readAndCombineJsonFiles() { + const dataContext = require.context('./', true, /\.json$/) + + let combinedData = {} + dataContext.keys().forEach((key) => { + const jsonData = dataContext(key) + combinedData = {...combinedData, ...jsonData} + }) + + return combinedData +} // There may have some un-translated content. Always fill in the gaps with EN JSON. // No need for a defaultMessage prop when render a FormattedMessage component. -export default Object.assign({}, enJson, { - ...debuggerJson, - ...filePanelJson, - ...homeJson, - ...panelJson, - ...pluginManagerJson, - ...searchJson, - ...settingsJson, - ...solidityJson, - ...terminalJson, - ...udappJson, - ...solidityUnitTestingJson, - ...permissionHandlerJson, - ...solUmlGenJson, - ...remixAppJson, - ...remixUiTabsJson, -}) +export default Object.assign({}, enJson, readAndCombineJsonFiles()) diff --git a/apps/remix-ide/src/app/tabs/locales/zh/index.js b/apps/remix-ide/src/app/tabs/locales/zh/index.js index 1acd2ba1be..d1dbf937cd 100644 --- a/apps/remix-ide/src/app/tabs/locales/zh/index.js +++ b/apps/remix-ide/src/app/tabs/locales/zh/index.js @@ -1,38 +1,17 @@ -import debuggerJson from './debugger.json'; -import filePanelJson from './filePanel.json'; -import homeJson from './home.json'; -import panelJson from './panel.json'; -import pluginManagerJson from './pluginManager.json'; -import searchJson from './search.json'; -import settingsJson from './settings.json'; -import solidityJson from './solidity.json'; -import terminalJson from './terminal.json'; -import udappJson from './udapp.json'; -import solidityUnitTestingJson from './solidityUnitTesting.json'; -import permissionHandlerJson from './permissionHandler.json'; -import solUmlGenJson from './solUmlGen.json' -import remixAppJson from './remixApp.json' -import remixUiTabsJson from './remixUiTabs.json' -import enJson from '../en'; -import circuitJson from './circuit.json'; +import enJson from '../en' + +function readAndCombineJsonFiles() { + const dataContext = require.context('./', true, /\.json$/) + + let combinedData = {} + dataContext.keys().forEach((key) => { + const jsonData = dataContext(key) + combinedData = {...combinedData, ...jsonData} + }) + + return combinedData +} // There may have some un-translated content. Always fill in the gaps with EN JSON. // No need for a defaultMessage prop when render a FormattedMessage component. -export default Object.assign({}, enJson, { - ...debuggerJson, - ...filePanelJson, - ...homeJson, - ...panelJson, - ...pluginManagerJson, - ...searchJson, - ...settingsJson, - ...solidityJson, - ...terminalJson, - ...udappJson, - ...solidityUnitTestingJson, - ...permissionHandlerJson, - ...solUmlGenJson, - ...remixAppJson, - ...remixUiTabsJson, - ...circuitJson -}) +export default Object.assign({}, enJson, readAndCombineJsonFiles())