diff --git a/src/locales/de-CH/default.js b/src/locales/de-CH/default.js index b0c24f981..267f6a275 100644 --- a/src/locales/de-CH/default.js +++ b/src/locales/de-CH/default.js @@ -1,4 +1,5 @@ -export default Object.assign( +import Utils from '../../utils'; +export default Utils.mergeDeep( { fields: require('../de/fields.json'), }, diff --git a/src/locales/de/default.js b/src/locales/de/default.js index 1853921fe..485258b64 100644 --- a/src/locales/de/default.js +++ b/src/locales/de/default.js @@ -1,4 +1,5 @@ -export default Object.assign( +import Utils from '../../utils'; +export default Utils.mergeDeep( { fields: require('./fields.json'), }, diff --git a/src/locales/en/default.js b/src/locales/en/default.js index 376314241..7dfdeb8ee 100644 --- a/src/locales/en/default.js +++ b/src/locales/en/default.js @@ -1,4 +1,5 @@ -export default Object.assign( +import Utils from '../../utils'; +export default Utils.mergeDeep( // Don't import the fields as it's a 1:1 mapping anyway // { fields: require('./fields.json') }, require('./texts.json'), diff --git a/src/locales/es/default.js b/src/locales/es/default.js index 1853921fe..485258b64 100644 --- a/src/locales/es/default.js +++ b/src/locales/es/default.js @@ -1,4 +1,5 @@ -export default Object.assign( +import Utils from '../../utils'; +export default Utils.mergeDeep( { fields: require('./fields.json'), }, diff --git a/src/locales/fr-CA/default.js b/src/locales/fr-CA/default.js index 1da4afb03..b8c426bf0 100644 --- a/src/locales/fr-CA/default.js +++ b/src/locales/fr-CA/default.js @@ -1,4 +1,5 @@ -export default Object.assign( +import Utils from '../../utils'; +export default Utils.mergeDeep( { fields: require('../fr/fields.json'), }, diff --git a/src/locales/fr-CH/default.js b/src/locales/fr-CH/default.js index 1da4afb03..b8c426bf0 100644 --- a/src/locales/fr-CH/default.js +++ b/src/locales/fr-CH/default.js @@ -1,4 +1,5 @@ -export default Object.assign( +import Utils from '../../utils'; +export default Utils.mergeDeep( { fields: require('../fr/fields.json'), }, diff --git a/src/locales/fr/default.js b/src/locales/fr/default.js index 1853921fe..485258b64 100644 --- a/src/locales/fr/default.js +++ b/src/locales/fr/default.js @@ -1,4 +1,5 @@ -export default Object.assign( +import Utils from '../../utils'; +export default Utils.mergeDeep( { fields: require('./fields.json'), }, diff --git a/src/locales/it-CH/default.js b/src/locales/it-CH/default.js index 793fdee34..246a85553 100644 --- a/src/locales/it-CH/default.js +++ b/src/locales/it-CH/default.js @@ -1,4 +1,5 @@ -export default Object.assign( +import Utils from '../../utils'; +export default Utils.mergeDeep( { fields: require('../it/fields.json'), }, diff --git a/src/locales/it/default.js b/src/locales/it/default.js index 1853921fe..485258b64 100644 --- a/src/locales/it/default.js +++ b/src/locales/it/default.js @@ -1,4 +1,5 @@ -export default Object.assign( +import Utils from '../../utils'; +export default Utils.mergeDeep( { fields: require('./fields.json'), }, diff --git a/src/locales/ro/default.js b/src/locales/ro/default.js index 1853921fe..485258b64 100644 --- a/src/locales/ro/default.js +++ b/src/locales/ro/default.js @@ -1,4 +1,5 @@ -export default Object.assign( +import Utils from '../../utils'; +export default Utils.mergeDeep( { fields: require('./fields.json'), }, diff --git a/src/utils.js b/src/utils.js index 31bf85456..c08334eed 100644 --- a/src/utils.js +++ b/src/utils.js @@ -398,4 +398,31 @@ export default class Utils { return Boolean(data['stac_extensions'].find(uri => regexp.test(uri))); } + /** + * Deep merge two objects. + * @param target + * @param ...sources + */ + static mergeDeep(target, ...sources) { + if (!sources.length) { + return target; + } + const source = sources.shift(); + + if (Utils.isObject(target) && Utils.isObject(source)) { + for (const key in source) { + if (Utils.isObject(source[key])) { + if (!target[key]) { + Object.assign(target, { [key]: {} }); + } + Utils.mergeDeep(target[key], source[key]); + } else { + Object.assign(target, { [key]: source[key] }); + } + } + } + + return Utils.mergeDeep(target, ...sources); + } + } \ No newline at end of file